<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class DailyBranchReport extends Model
{
    protected $fillable = [
        'business_id', 'branch_id', 'daily_closing_id', 'report_date', 'closing_number', 'subject',
        'body_html', 'body_text', 'snapshot', 'checksum', 'generated_at',
    ];

    protected function casts(): array
    {
        return [
            'report_date' => 'date',
            'snapshot' => 'array',
            'generated_at' => 'datetime',
        ];
    }

    public function business(): BelongsTo { return $this->belongsTo(Business::class); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function dailyClosing(): BelongsTo { return $this->belongsTo(DailyClosing::class); }
    public function deliveries(): HasMany { return $this->hasMany(DailyBranchReportDelivery::class); }
}
