<?php

namespace App\Policies;

use App\Models\DailyClosing;
use App\Models\User;
use App\Services\BranchAccessService;
use App\Support\Authorization\PermissionName;

class DailyClosingPolicy
{
    public function __construct(private BranchAccessService $branchAccess) {}

    public function view(User $user, DailyClosing $dailyClosing): bool
    {
        return $user->can(PermissionName::CASH_CLOSING_VIEW->value)
            && $this->branchAccess->canAccessBranch($user, (int) $dailyClosing->branch_id);
    }

    public function confirm(User $user, DailyClosing $dailyClosing): bool
    {
        return $user->can(PermissionName::DAILY_CLOSING_CONFIRM->value)
            && $this->branchAccess->canAccessBranch($user, (int) $dailyClosing->branch_id);
    }
}
