<?php

namespace App\Http\Requests;

use App\Models\CoursewarePartner;
use Illuminate\Foundation\Http\FormRequest;

class CoursewarePartnerRequest extends FormRequest
{
    use PartnerAccountRules;

    public function authorize(): bool
    {
        $partner = $this->route('courseware_partner');

        return $partner
            ? $this->user()->can('update', $partner)
            : $this->user()->can('create', CoursewarePartner::class);
    }

    public function rules(): array
    {
        $ignoreUserId = $this->route('courseware_partner')?->user_id;

        return array_merge($this->accountRules($ignoreUserId), [
            'institute_name' => ['nullable', 'string', 'max:255'],
            'official_building' => ['nullable', 'string', 'max:255'],
            'official_street' => ['nullable', 'string', 'max:255'],
            'official_city' => ['nullable', 'string', 'max:255'],
            'official_state' => ['nullable', 'string', 'max:255'],
            'official_postal_code' => ['nullable', 'string', 'max:50'],
            'official_country' => ['nullable', 'string', 'max:255'],
            'official_email' => ['nullable', 'email', 'max:255', 'lowercase'],
            'official_phone' => ['nullable', 'string', 'max:50'],
            'website' => ['nullable', 'string', 'max:255'],
            'second_contact_name' => ['nullable', 'string', 'max:255'],
            'second_contact_email' => ['nullable', 'email', 'max:255', 'lowercase'],
            'second_contact_phone' => ['nullable', 'string', 'max:50'],
            'mobile' => ['nullable', 'string', 'max:50'],
            'practical_lab_area' => ['nullable', 'string', 'max:255'],
            'theory_classroom_area' => ['nullable', 'string', 'max:255'],
            'courseware_category_id' => ['nullable', 'integer', 'exists:courseware_categories,id'],
            'requirements' => ['nullable', 'string'],
            'authorised_partner_id' => ['nullable', 'integer', 'exists:authorised_partners,id'],
        ]);
    }
}
