<?php

namespace Modules\Lpj\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Location\Models\City;
use Modules\Location\Models\District;
use Modules\Location\Models\Province;
use Modules\Location\Models\Village;
use Modules\Lpj\Database\Factories\PemilikJaminanFactory;

class PemilikJaminan extends Base
{
    protected $table    = 'pemilik_jaminan';
    protected $fillable = [
        'debiture_id',
        'hubungan_pemilik_jaminan_id',
        'name',
        'npwp',
        'email',
        'phone',
        'nomor_id',
        'province_code',
        'city_code',
        'district_code',
        'village_code',
        'postal_code',
        'address',
        'status',
        'authorized_at',
        'authorized_status',
        'authorized_by',
        'detail_sertifikat',
    ];

    public function province()
    {
        return $this->belongsTo(Province::class, 'province_code', 'code');
    }

    public function city()
    {
        return $this->belongsTo(City::class, 'city_code', 'code');
    }

    public function district()
    {
        return $this->belongsTo(District::class, 'district_code', 'code');
    }

    public function village()
    {
        return $this->belongsTo(Village::class, 'village_code', 'code');
    }

    public function debitur(){
        return $this->belongsTo(Debiture::class, 'debiture_id', 'id');
    }

    public function dokumen(){
        return $this->hasMany(DokumenJaminan::class, 'pemilik_jaminan_id', 'id');
    }

    public function hubungan_pemilik(){
        return $this->belongsTo(HubunganPemilikJaminan::class, 'hubungan_pemilik_jaminan_id', 'id');
    }
}
