<?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 Contractor extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'business_name',
        'short_name',
        'business_type',
        'oap_status',
        'oap_verified_at',
        'oap_verified_by',
        'established_year',
        'operational_year',
        'address',
        'province',
        'regency',
        'district',
        'village',
        'postal_code',
        'phone',
        'fax',
        'mobile',
        'email',
        'website',
        'logo_url',
        'skp_remaining',
        'rating_avg',
        'is_blacklisted',
        'is_probation',
        'probation_end_date',
        'is_active',
    ];

    protected $casts = [
        'oap_verified_at' => 'datetime',
        'is_blacklisted' => 'boolean',
        'is_probation' => 'boolean',
        'is_active' => 'boolean',
        'rating_avg' => 'decimal:2',
    ];

    // 👇 TAMBAHKAN RELASI INI!
    public function contracts(): HasMany
    {
        return $this->hasMany(Contract::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function legal()
    {
        return $this->hasOne(ContractorLegal::class);
    }

    public function bankAccounts()
    {
        return $this->hasMany(ContractorBankAccount::class);
    }

    public function directors()
    {
        return $this->hasMany(ContractorDirector::class);
    }

    public function sbu()
    {
        return $this->hasMany(ContractorSBU::class);
    }

    public function documents()
    {
        return $this->hasMany(ContractorDocument::class);
    }

    public function experiences()
    {
        return $this->hasMany(ContractorExperience::class);
    }
}