<?php

namespace App\Http\Requests\V1\Card;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'card_company' => ['required', 'string', 'max:50'],
            'card_number' => ['required', 'string', 'regex:/^\d{13,19}$/'],
            'expiry_date' => ['required', 'string', 'regex:/^(0[1-9]|1[0-2])\/\d{2}$/'],
            'card_password' => ['nullable', 'string', 'size:2', 'regex:/^\d{2}$/'],
            'card_name' => ['required', 'string', 'max:100'],
            'status' => ['nullable', 'string', 'in:active,inactive'],
            'assigned_user_id' => ['nullable', 'integer', 'exists:users,id'],
        ];
    }

    public function messages(): array
    {
        return [
            'card_company.required' => __('validation.required', ['attribute' => __('validation.attributes.card_company')]),
            'card_number.required' => __('validation.required', ['attribute' => __('validation.attributes.card_number')]),
            'card_number.regex' => __('validation.card_number_format'),
            'expiry_date.required' => __('validation.required', ['attribute' => __('validation.attributes.expiry_date')]),
            'expiry_date.regex' => __('validation.expiry_date_format'),
            'card_password.size' => __('validation.card_password_format'),
            'card_password.regex' => __('validation.card_password_format'),
            'card_name.required' => __('validation.required', ['attribute' => __('validation.attributes.card_name')]),
        ];
    }

    public function attributes(): array
    {
        return [
            'card_company' => __('validation.attributes.card_company'),
            'card_number' => __('validation.attributes.card_number'),
            'expiry_date' => __('validation.attributes.expiry_date'),
            'card_password' => __('validation.attributes.card_password'),
            'card_name' => __('validation.attributes.card_name'),
            'status' => __('validation.attributes.status'),
            'assigned_user_id' => __('validation.attributes.assigned_user_id'),
        ];
    }
}
