module Concernz

module Claim
  extend ActiveSupport::Concern
  included do
    self.primary_key = 'claim_id'

    # maybe Claim concerns Incident and maybe Incident was independently witnessed by Witness and Witness is a kind of Person
    belongs_to :person_via_incident_witness, :class_name => 'Person', :foreign_key => :incident_witness_id

    # Claim concerns Incident and Incident is a Vehicle Incident
    has_one :vehicle_incident_via_incident, :class_name => 'VehicleIncident', :foreign_key => :incident_claim_id, :dependent => :destroy
  end
end

end

module Concernz

module Person
  extend ActiveSupport::Concern
  included do
    self.primary_key = 'person_id'

    # Person is a Witness and maybe Witness saw Incident and maybe Incident resulted in Claim
    has_many :claims_via_incident_witness, :class_name => 'Claim', :foreign_key => :incident_witness_id, :dependent => :destroy

    # Person is a Driver and maybe Vehicle Incident occurred while Driver was in charge
    has_many :vehicle_incidents_via_driver, :class_name => 'VehicleIncident', :foreign_key => :driver_id, :dependent => :destroy

    validates :person_name, :presence => true
  end
end

end

module Concernz

module VehicleIncident
  extend ActiveSupport::Concern
  included do
    self.primary_key = 'incident_claim_id'

    # Vehicle Incident is a kind of Incident and Incident resulted in Claim
    belongs_to :claim_via_incident, :class_name => 'Claim', :foreign_key => :incident_claim_id

    # maybe Vehicle Incident occurred while Driver was in charge and Driver is a kind of Person
    belongs_to :person_via_driver, :class_name => 'Person', :foreign_key => :driver_id

    validates :incident_claim_id, :presence => true
  end
end

end