<?php

defined('ABSPATH') || exit; // Prevent direct file access.

use SGC\eGiftCard\Hooks\Handler\ActionHooksHandler;
use SGC\eGiftCard\Hooks\Handler\CleanupHandler;
//Add the Gift Amount to the cart
add_action('woocommerce_before_calculate_totals', [ActionHooksHandler::class, 'set_custom_gift_card_price'], 10);

// Save custom gift card data in the order when the checkout is completed
add_action('woocommerce_checkout_create_order_line_item', [ActionHooksHandler::class, 'save_gift_card_data_in_order'], 10, 4);

//Generate Gift Code and store the information to the database table (gift_codes)
add_action('woocommerce_order_status_completed', [ActionHooksHandler::class, 'generate_gift_code_on_order_complete']);

//Deduct Gift Balance from total
add_action('woocommerce_cart_calculate_fees', [ActionHooksHandler::class, 'apply_gift_card_balance']);

//Update User gift card wallet balance
add_action('woocommerce_thankyou', [ActionHooksHandler::class, 'update_gift_card_balance_after_purchase']);

// Auto-complete gift card orders
add_action('woocommerce_thankyou', [ActionHooksHandler::class, 'auto_complete_gift_card_orders'], 10, 1);


//Custom Hooks
add_action('sgc_smart_gift_card_data_after_confirm_order', [ActionHooksHandler::class, 'gift_code_created']);

//Hooks to check mail need to send or not
add_action('smart_gift_card_hourly_tasks', [ActionHooksHandler::class, 'gift_card_hourly_tasks']);
//Hooks to check mail need to send or not
add_action('smart_gift_card_daily_tasks', [CleanupHandler::class, 'may_be_delete_uploaded_files']);

add_action(
    'wp_ajax_sgc_renew_rest_nonce',
    function () {
        wp_send_json(
            array(
                'nonce' => wp_create_nonce('wp_rest'),
            ),
            200
        );
    }
);
