<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class DailyClosing extends Model
{
    use HasFactory;

    protected $fillable = [
        'cash_drawer_id', 'closing_date', 'opening_balance', 'sales_total',
        'payments_total', 'expenses_total', 'refunds_total', 'cash_in', 'cash_out',
        'expected_cash', 'actual_cash', 'difference', 'notes', 'closed_by',
    ];

    protected $casts = [
        'closing_date' => 'date',
        'opening_balance' => 'decimal:2',
        'sales_total' => 'decimal:2',
        'payments_total' => 'decimal:2',
        'expenses_total' => 'decimal:2',
        'refunds_total' => 'decimal:2',
        'cash_in' => 'decimal:2',
        'cash_out' => 'decimal:2',
        'expected_cash' => 'decimal:2',
        'actual_cash' => 'decimal:2',
        'difference' => 'decimal:2',
    ];

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

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