<?php

namespace App\Http\Requests;

use App\Enums\DefaultStatusEnum;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CountryRequest extends FormRequest
{
    public function rules(): array
    {
        $rules = [
            'name'   => 'sometimes|string|max:255|unique:countries,name',
            'code'   => 'sometimes|string|min:2|max:3|unique:countries,code',
            'status' => ['sometimes', Rule::enum(DefaultStatusEnum::class)],
        ];

        if ($this->isMethod('post')) {
            $rules['name']   = 'required|string|max:255|unique:countries,name';
            $rules['code']   = 'required|string|min:2|max:3|unique:countries,code';
            $rules['status'] = ['required', Rule::enum(DefaultStatusEnum::class)];
        }

        return $rules;
    }
}
