<?php

namespace App\Components\Solicitor;

use App\Models\Solicitor\Solicitor;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;

class Create extends Component {
    use AuthorizesRequests;
    public $name = '';
    public $domain = '';

    public function mount(): void {
        $this->authorize('solicitors.create');
    }

    public function save() {
        $this->authorize('solicitors.create');
        $this->validate();

        Solicitor::create([
            'name' => $this->name,
            'domain' => $this->domain,
        ]);

        $this->reset();
    }

    public function render() {
        return view('components.solicitor.create');
    }

    protected function rules() {
        return [
            'name' => ['required', 'string', 'max:255'],
            'domain' => ['nullable', 'string', 'max:255'],
        ];
    }
}
