<?php

namespace App\Policies;

use App\Models\Quotation;
use App\Models\User;

class QuotationPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->hasPermission('quotations.view');
    }

    public function view(User $user, Quotation $quotation): bool
    {
        return $user->hasPermission('quotations.view');
    }

    public function create(User $user): bool
    {
        return $user->hasPermission('quotations.create');
    }

    public function update(User $user, Quotation $quotation): bool
    {
        return $user->hasPermission('quotations.update') && $quotation->isEditable();
    }

    public function delete(User $user, Quotation $quotation): bool
    {
        return $user->hasPermission('quotations.update') && $quotation->isEditable();
    }

    public function issue(User $user, Quotation $quotation): bool
    {
        return $user->hasPermission('quotations.issue') && $quotation->isEditable();
    }

    public function accept(User $user, Quotation $quotation): bool
    {
        return $user->hasPermission('quotations.accept')
            && in_array($quotation->status->value, ['draft', 'sent'], true);
    }

    public function convert(User $user, Quotation $quotation): bool
    {
        return $user->hasPermission('quotations.convert') && $quotation->isConvertible();
    }
}
