<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Province;
use Illuminate\Http\Request;

class Contracts extends Model
{
    use HasFactory;
    public static function boot()
    {
        parent::boot();

        self::creating(function($model){
        });

        self::created(function($model){
            auth()->user()->addActivityComplete(1001,$model);
        });

        self::updating(function($model){
            auth()->user()->addActivityComplete(1002,$model);
        });

        self::updated(function($model){
        });

        self::deleting(function($model){
            auth()->user()->addActivityComplete(1003,$model);
        });

        self::deleted(function($model){
        });
    }

    // protected $table = 'contracts';
    protected $fillable = [
        'province_id',
        'province_fa',
        'office_id',
        'office_fa',
        'title',
        'status_id',
        'status_fa',
        'contract_date',
        'contract_mojavez_data_meli',
        'contract_mojavez_data_setad',
        'contract_mojavez',
        'contract_mojavez_fa',
        'contract_tarh',
        'contract_credit_national',
        'contract_credit_province',
        'contract_credit',
        'contract_peymankar',
        'contract_moshaver_tarahi',
        'contract_moshaver_nezarat',
        'unique_id',
        'created_at_fa',
        'contract_mojavez_array',
        'contract_mojavez_data_meli_array',
        'contract_mojavez_data_setad_array',
        'contract_credit_national_array',
        'contract_tarh_array',
        'contract_mojavez_fa_array',
        'contract_credit_headquarter',
        // 'status',
        'user_id',
        'national_credit_license',
        'province_credit_license',
        'headquarter_issued_license',
        'province_issued_license'
    ];

    public function subitems()
    {
        return $this->hasMany(ContractSubItems::class, 'contract_id');
    }

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

    }

}