<?php

namespace App\Models\Finance;

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

class Invoice extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'invoice_no', 'customer_id', 'type', 'amount',
        'tax_amount', 'title', 'tax_no', 'related_type', 'related_id',
        'status', 'operator_id', 'issued_at',
    ];

    protected function casts(): array
    {
        return [
            'type' => 'integer',
            'status' => 'integer',
            'amount' => 'decimal:2',
            'tax_amount' => 'decimal:2',
            'issued_at' => 'datetime',
        ];
    }

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

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