<?php

namespace App\Http\Requests\Member;

use Illuminate\Foundation\Http\FormRequest;

// ══════════════════════════════════════════════════════════════════
//  InPractice — StoreCvProfileRequest
//  Location: app/Http/Requests/Member/StoreCvProfileRequest.php
//
//  Validates creating or updating a CV profile.
//  All fields use sometimes so the member can update partially.
//  Personal info (name, phone, email) lives on the User model —
//  never submitted here.
// ══════════════════════════════════════════════════════════════════

class StoreCvProfileRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true; // EnsureMember middleware handles auth
    }

    public function rules(): array
    {
        return [
            'job_title'            => ['sometimes', 'required', 'string', 'max:100'],
            'current_industry'     => ['sometimes', 'required', 'string', 'max:100'],
            'years_experience'     => ['sometimes', 'required', 'integer', 'min:0', 'max:50'],
            'experience_level'     => ['sometimes', 'required', 'string', 'in:student,fresh,junior,mid,senior'],
            'skills'               => ['sometimes', 'required', 'array', 'min:1', 'max:20'],
            'skills.*'             => ['required', 'string', 'max:50'],
            'hub_ids'              => ['sometimes', 'required', 'array', 'min:1'],
            'hub_ids.*'            => ['required', 'integer', 'exists:hubs,id'],
            'education_level'      => ['sometimes', 'required', 'string', 'in:diploma,bachelor,master,phd'],
            'education_field'      => ['sometimes', 'nullable', 'string', 'max:100'],
            'location_country'     => ['sometimes', 'required', 'string', 'max:100'],
            'location_city'        => ['sometimes', 'nullable', 'string', 'max:100'],
            'summary'              => ['sometimes', 'nullable', 'string', 'max:500'],
            'preferred_sectors'    => ['sometimes', 'nullable', 'array'],
            'preferred_sectors.*'  => ['required', 'string', 'max:100'],
            'job_type_preference'  => ['sometimes', 'nullable', 'string', 'in:full_time,part_time,both'],
            'open_to_relocation'   => ['sometimes', 'boolean'],
            'is_visible'           => ['sometimes', 'boolean'],
        ];
    }

    public function messages(): array
    {
        return [
            'skills.min'    => __('cv.validation.skills_min'),
            'hub_ids.min'   => __('cv.validation.hub_required'),
            'hub_ids.*.exists' => __('cv.validation.hub_invalid'),
        ];
    }
}
