<?php

namespace App\Classes\Modules\Rewards\Standards\Validators;


use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
use App\Models\Reward;

class RewardValidation extends AbstractValidation
{
    /**
     * @param RewardObject $object
     * @return array
     */
    protected function data($object): array {

        $data = [
            'name'=> $object->getName(),
            'description' => $object->getDescription(),
        ];

        return $data;
    }

    /**
     * @param null|string $type
     * @return array
     */
    protected function rules(): array {
        return [
            'name' => [
                'required',
                function ($attribute, $value, $fail) {
                    // Check if reward name already exists in the database
                    $existingMilestone = Reward::where('name', $value)->first();
                    if ($existingMilestone) {
                        $fail("The {$attribute} reward name already exists in the database.");
                    }
                },
            ],
            'description' => [
                'required',
            ]
        ];
    }

    /**
     * @return array
     */
    protected function messages(): array {
        return [];
    }

}
