<?php

namespace SGC\eGiftCard\Http\Request;

defined( 'ABSPATH' ) || exit; // Prevent direct file access.
/**
 * Class ValidatorHandler
 *
 * Handles validation of various request data for the eGift Card system.
 */
class ValidatorHandler extends Validator {
    
    /**
     * Validate add to cart data.
     *
     * @param Request $request The request object.
     *
     * @return array List of validation errors.
     */
    public static function validateCartData( Request $request ) {
        return $request->validate(
            $request->only(['gift_amount', 'recipient_name', 'recipient_email', 'sender_name', 'delivery_date', 'product_id']),
            [
                'gift_amount'       => 'required',
                'recipient_name'    => 'required',
                'recipient_email'   => 'required|email',
                'sender_name'       => 'required',
                'delivery_date'     => 'required',
                'product_id'        => 'required',
            ],
            [
                'gift_amount.required'       => __( 'Gift amount is required.', 'smart-gift-card' ),
                'recipient_name.required'    => __( 'Receiver name is required.', 'smart-gift-card' ),
                'recipient_email.required'   => __( 'Receiver email is required.', 'smart-gift-card' ),
                'recipient_email.email'      => __( 'Receiver email is not a valid email address.', 'smart-gift-card' ),
                'sender_name.required'       => __( 'Sender name is required.', 'smart-gift-card' ),
                'delivery_date.required'     => __( 'Delivery date is required.', 'smart-gift-card' ),
                'product_id.required'        => __( 'Gift product is required. Set from general settings.', 'smart-gift-card' ),
            ]
        );
    }

    /**
     * Validate general settings data.
     *
     * @param Request $request The request object.
     *
     * @return array List of validation errors.
     */
    public static function validateGeneralSettings( Request $request ) {
        return $request->validate(
            $request->only(['gift_card_page_id', 'redeem_gift_page_id', 'gift_product_id', 'gift_amount', 'code_validation']),
            [
                'gift_card_page_id'    => 'required',
                'redeem_gift_page_id'  => 'required',
                'gift_product_id'      => 'required',
                'gift_amount'          => 'required',
                'code_validation'      => 'required',
            ],
            [
                'gift_card_page_id.required'    => __( 'Gift card page is required.', 'smart-gift-card' ),
                'redeem_gift_page_id.required'  => __( 'Redeem gift page is required.', 'smart-gift-card' ),
                'gift_product_id.required'      => __( 'Gift card product is required.', 'smart-gift-card' ),
                'gift_amount.required'          => __( 'Gift amount is required.', 'smart-gift-card' ),
                'code_validation.required'      => __( 'Gift Code validity require.', 'smart-gift-card' ),
            ]
        );
    }

    /**
     * Validate advance settings data.
     *
     * @param Request $request The request object.
     *
     * @return array List of validation errors.
     */
    public static function validateAdvanceSettings( Request $request ) {
        return $request->validate(
            $request->only(['sgc_allow_with_others', 'sgc_allow_custom_upload', 'sgc_allow_video_selection']),
            [
                'sgc_allow_with_others'    => 'required',
                'sgc_allow_custom_upload'  => 'required',
                'sgc_allow_video_selection'=> 'required',
            ],
            [
                'sgc_allow_with_others.required'    => __( 'Allow with other products setting is required.', 'smart-gift-card' ),
                'sgc_allow_custom_upload.required'  => __( 'Allow custom upload setting is required.', 'smart-gift-card' ),
                'sgc_allow_video_selection.required'=> __( 'Allow video selection setting is required.', 'smart-gift-card' ),
            ]
        );
    }
    
    /**
     * Validate event design request data.
     *
     * @param Request $request The request object.
     *
     * @return array List of validation errors.
     */
    public static function validateEventDesignRequest ( $request ) 
    {
        return $request->validate(
            $request->only(['event_name', 'design_name', 'event_file_type']),
            [
                'event_name' => 'required',
                'design_name' => 'required',
                'event_file_type' => 'required'
            ],
            [
                'event_name.required' => __('Event Name is required', 'smart-gift-card'),
                'design_name.required' => __('Design Name is required', 'smart-gift-card'),
                'event_file_type.required' => __('File Type is required', 'smart-gift-card'),
            ]
        );
    }

    public static function validateDesignSettings( $request ) 
    {
        return $request->validate(
            $request->only(['gift_amount_btn_color', 'add_to_cart_btn_color', 'redeem_btn_color', 'initial_message', 'gift_card_background']),
            [
                'gift_amount_btn_color' => 'required',
                'add_to_cart_btn_color' => 'required',
                'redeem_btn_color'      => 'required',
                'initial_message'       => 'required',
            ],
            [
                'gift_amount_btn_color.required' => __('Gift Amount Button Color is required', 'smart-gift-card'),
                'add_to_cart_btn_color.required' => __('Add to Cart Button Color is required', 'smart-gift-card'),
                'redeem_btn_color.required'      => __('Redeem Button Color is required', 'smart-gift-card'),
                'initial_message.required'       => __('Initial Message is required', 'smart-gift-card'),
            ]
        );
    }
}