<?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;

    class Debiture extends Base
    {
        protected $table    = 'debitures';
        protected $fillable = [
            'branch_id',
            'cif',
            'name',
            'registered_at',
            'npwp',
            'email',
            'phone',
            'nomor_rekening',
            'province_code',
            'city_code',
            'district_code',
            'village_code',
            'postal_code',
            'address',
            'status',
            'authorized_at',
            'authorized_status',
            'authorized_by'
        ];

        public function branch()
        {
            return $this->belongsTo(Branch::class, 'branch_id', 'id');
        }

        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 documents(){
            return $this->hasMany(DokumenJaminan::class);
        }

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

        public function laporanAdminKredit(): HasMany
        {
            return $this->hasMany(LaporanAdminKredit::class);
        }

    }
