<?php
namespace EasyRestaurantManager\Http\Requests;

class StoreCouponRequest extends RequestGuard {
    
    /**
     * Define validation rules
     */
    public function rules() {
        return [
            'name' => 'required|string|max:255',
            'code' => 'nullable|string|max:100|unique:discounts,code',
            'discount_type' => 'required|string',
            'discount_value' => 'required|numeric|min:0', 
            'status' => 'required|string', 
            'expiration_date' => 'nullable|date|after:today',
            'added_date' => 'nullable|date',
        ];
    }

    /**
     * Define custom validation messages
     */
    public function messages() {
        return [
            'name.required' => esc_html__('Category name is required.', 'easy-restaurant-manager'),
            'name.string' => esc_html__('Category name must be a string.', 'easy-restaurant-manager'),
            'name.max' => esc_html__('Category name must not exceed 255 characters.', 'easy-restaurant-manager'),
            'code.unique' => "Discount code must be unique.",
            'discount_type.in' => "Discount type must be 'fixed' or 'percentage'.",
            'discount_value.required' => "Discount value is required.",
            'discount_value.min' => "Discount value cannot be negative.",
            'status.required' => "Discount status is required.",
            'expiration_date.after' => "Expiration date must be in the future."
        ];
    }

    /**
     * Define sanitization rules
     */
    public function sanitize() {
        return [
            'name' => 'sanitize_text_field',
            'code' => 'sanitize_text_field',
            'discount_type' => 'sanitize_text_field',
            'discount_value' => 'sanitize_text_field',
            'expiration_date' => 'sanitize_text_field',
            'added_date' => 'sanitize_text_field',
            'status' => 'sanitize_text_field',
        ];
    }
}
