<?php

namespace App\Policies;

use App\Models\Creator;
use App\Models\Organization;
use App\Models\User;

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

    public function view(User $user, Creator $creator, ?Organization $organization = null): bool
    {
        if (!$this->belongsToOrganization($user, $organization)) {
            return false;
        }

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

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

    public function update(User $user, Creator $creator, ?Organization $organization = null): bool
    {
        if (!$this->belongsToOrganization($user, $organization)) {
            return false;
        }

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

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

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

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

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

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