<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Address extends Model
{
    use HasFactory;

    //link to table
    protected $table = "ADDRESS";

    //link to PK
    protected $primaryKey= 'RID';

    //dates
    const CREATED_AT = 'DATE_CREATED';
    const UPDATED_AT = 'DATE_MODIFIED';

    /**
    * Relate to human
     */
    public function humanBirthAddress(): HasMany
    {
        //birth address
        return $this->hasMany(Human::class, 'adrref_birth', 'rid');
    }

    /**
     * Relate to human
     */
    public function humanLiveAddress(): HasMany
    {
        //birth address
        return $this->hasMany(Human::class, 'adrref_live', 'rid');
    }

    /**
     * Relate to location
     */
    public function addressLocation(): BelongsTo
    {
        return $this->belongsTo(Location::class, 'location', 'rid');
    }

    /**
     * Relate to District
     */
    public function addressDistrict(): BelongsTo
    {
        return $this->belongsTo(DistrictMapping::class, 'distr','iprs_district_id');
    }

    /**
     * Relate to Address comp
     */
    public function adresComp(): BelongsTo
    {
        return $this->belongsTo(AdresComp::class, 'distr','rid');
    }
}
