<?php

namespace App\Policies;

use App\Models\AuditLog;
use App\Models\Organization;
use App\Models\User;

class AuditLogPolicy extends BasePolicy
{
    public function viewAny(User $user, ?Organization $organization = null): bool
    {
        return $this->belongsToOrganization($user, $organization);
    }

    public function view(User $user, AuditLog $auditLog, ?Organization $organization = null): bool
    {
        return $this->resourceBelongsToOrganization($auditLog, $organization, $user);
    }

    public function delete(User $user, AuditLog $auditLog, ?Organization $organization = null): bool
    {
        if (!$this->isOwnerOrAdmin($user)) {
            return false;
        }

        return $this->resourceBelongsToOrganization($auditLog, $organization, $user);
    }

    public function deleteAll(User $user, ?Organization $organization = null): bool
    {
        return $this->isOwnerOrAdmin($user) && $this->belongsToOrganization($user, $organization);
    }

    public function export(User $user, ?Organization $organization = null): bool
    {
        return $this->viewAny($user, $organization);
    }
}
