<?php

    namespace Modules\Lpj\Models;

    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\DokumenJaminanFactory;

    class DokumenJaminan extends Base
    {
        protected $table    = 'dokumen_jaminan';
        protected $fillable = [
            'debiture_id',
            'permohonan_id',
            'pemilik_jaminan_id',
            'jenis_jaminan_id',
            'province_code',
            'city_code',
            'district_code',
            'village_code',
            'postal_code',
            'address',
            'status',
            'authorized_at',
            'authorized_status',
            'authorized_by',
        ];

        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 debiture(){
            return $this->belongsTo(Debiture::class, 'debiture_id', 'id');
        }

        public function pemilik(){
            return $this->belongsTo(PemilikJaminan::class, 'pemilik_jaminan_id', 'id');
        }

        public function jenisJaminan(){
            return $this->belongsTo(JenisJaminan::class, 'jenis_jaminan_id', 'id');
        }

        public function permohonan(){
            return $this->belongsTo(Permohonan::class, 'permohonan_id', 'id');
        }

        public function detail(){
            return $this->hasMany(DetailDokumenJaminan::class, 'dokumen_jaminan_id', 'id');
        }
        public function inspeksi()
        {
            return $this->hasMany(Inspeksi::class, 'dokument_id', 'id');
        }
    }
