<?php

namespace App\Http\Requests\Account;

use App\Services\AccountService;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateAgreementsRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'agreements' => ['required', 'array', 'min:1'],
            'agreements.*.type' => ['required', 'string', Rule::in(array_keys(AccountService::getAgreementTypes()))],
            'agreements.*.agreed' => ['required', 'boolean'],
        ];
    }

    public function messages(): array
    {
        return [
            'agreements.required' => __('validation.required', ['attribute' => '약관 동의 정보']),
            'agreements.array' => __('validation.array', ['attribute' => '약관 동의 정보']),
            'agreements.*.type.required' => __('validation.required', ['attribute' => '약관 유형']),
            'agreements.*.type.in' => __('validation.in', ['attribute' => '약관 유형']),
            'agreements.*.agreed.required' => __('validation.required', ['attribute' => '동의 여부']),
            'agreements.*.agreed.boolean' => __('validation.boolean', ['attribute' => '동의 여부']),
        ];
    }
}
