<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

class CreatorStoreRequest extends CreatorRequest
{
    public function authorize(): bool
    {
        $organization = $this->attributes->get('current_organization');
        return $this->user()->can('create', [\App\Models\Creator::class, $organization]);
    }

    protected function creatorNameRule(): array
    {
        $orgBin = $this->getOrgBin();

        return [
            'required',
            'string',
            'max:255',
            Rule::unique('creators', 'creator_name')->where(function ($query) use ($orgBin) {
                if ($orgBin) {
                    $query->where('organization_id', $orgBin);
                }
            }),
        ];
    }
}
