<?php

namespace App\Models\Finance;

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

class FinanceRecord extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'record_no', 'category_id', 'type', 'amount',
        'pay_method', 'related_type', 'related_id', 'description',
        'audit_status', 'audit_user_id', 'audit_at', 'operator_id',
        'record_date',
    ];

    protected function casts(): array
    {
        return [
            'type' => 'integer',
            'pay_method' => 'integer',
            'audit_status' => 'integer',
            'amount' => 'decimal:2',
            'audit_at' => 'datetime',
            'record_date' => 'date',
        ];
    }

    public function category(): BelongsTo
    {
        return $this->belongsTo(FinanceCategory::class, 'category_id');
    }

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

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