<?php

namespace App\Policies;

use App\Models\Sale;
use App\Models\User;

class SalePolicy
{
    /**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return $user->can('ver_pos');
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, Sale $sale): bool
    {
        // El vendedor solo ve sus propias ventas
        if ($user->hasRole('Vendedor')) {
            return $sale->user_id === $user->id;
        }

        return $user->can('ver_pos');
    }

    /**
     * Determine whether the user can create models.
     */
    public function create(User $user): bool
    {
        return $user->can('ver_pos');
    }

    /**
     * Determine whether the user can update prices (Price Override).
     */
    public function overridePrice(User $user): bool
    {
        return $user->hasRole('Admin'); // O un permiso específico si se desea
    }
}
