<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\AssetAssignment;
use App\Models\User;

/**
 * Record-level rules for Assignments.
 *
 * Viewing and creating are open to every signed-in user, matching Assets and
 * Employees. There is no `update` or `delete` ability at all — not even for
 * masters — because AssetAssignment is immutable history; no route exists
 * that would ever ask this policy about either, which is a stronger guarantee
 * than a method that returns false.
 */
class AssignmentPolicy
{
    public function viewAny(User $actor): bool
    {
        return true;
    }

    public function view(User $actor, AssetAssignment $assignment): bool
    {
        return true;
    }

    public function create(User $actor): bool
    {
        return true;
    }

    /**
     * Open to every signed-in user, gated only by whether the custody period
     * is still open. ReturnController and AssignmentService both re-check
     * this same condition, so it holds even for a caller that skips this
     * policy entirely.
     */
    public function return(User $actor, AssetAssignment $assignment): bool
    {
        return $assignment->isActive();
    }
}
