<?php
namespace Daniv04\HaciendaPackage\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;


class GeneralRequest extends FormRequest
{

    public function authorize(): bool
    {
        return true;
    }


    public function rules(): array
    {
        return [
            'ReceiptType' => ['required', 'string', 'in:FE,FEE,FEC,TE,NC,ND,REP'],
            'IssueDate' => ['required', 'date'],
            'Payload' => ['required', 'array']
        ];
    }

    public function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(
            response()->json([
                'status' => 422,
                'message' => 'Validation Error',
                'errors' => $validator->errors()
            ], 422)
        );
    }
}