<?php

namespace App\Models\Crm;

use App\Models\User;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Contract extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'customer_id', 'contract_no', 'package_name',
        'total_amount', 'discount_amount', 'actual_amount',
        'days', 'check_in_date', 'check_out_date',
        'status', 'audit_user_id', 'audit_at', 'audit_remark',
        'remark', 'created_by',
    ];

    protected function casts(): array
    {
        return [
            'total_amount' => 'decimal:2',
            'discount_amount' => 'decimal:2',
            'actual_amount' => 'decimal:2',
            'days' => 'integer',
            'check_in_date' => 'date',
            'check_out_date' => 'date',
            'status' => 'integer',
            'audit_at' => 'datetime',
        ];
    }

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

    public function auditor(): BelongsTo
    {
        return $this->belongsTo(User::class, 'audit_user_id');
    }

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
