<?php



/**

 * Master helpers loaded at bootstrap. Egypt booking times: App\Libraries\EgyptTime (Africa/Cairo).

 *

 * @link https://codeigniter4.github.io/CodeIgniter4/

 */



use App\Libraries\EgyptTime;



if (! function_exists('ensure_egypt_php_timezone')) {

    function ensure_egypt_php_timezone(): void

    {

        EgyptTime::ensurePhpDefault();

    }

}



if (! function_exists('get_egypt_time')) {

    /**

     * Egypt DateTime (DST via Africa/Cairo / IANA). Use for tickets, temporarybooks, APIs, comparisons.

     *

     * @return \DateTime

     */

    function get_egypt_time($time = 'now')

    {

        return EgyptTime::parse($time === null || $time === '' ? 'now' : (string) $time);

    }

}



if (! function_exists('parse_egypt_wall_clock')) {

    /** Typed datetime from admin forms (hold_seats start/end, etc.) — Cairo wall clock. */

    function parse_egypt_wall_clock(?string $value): ?string

    {

        return EgyptTime::wallClock($value);

    }

}



if (! function_exists('egypt_now_sql')) {

    function egypt_now_sql(): string

    {

        return EgyptTime::nowSql();

    }

}



if (! function_exists('egypt_today')) {

    function egypt_today(): string

    {

        return EgyptTime::today();

    }

}



if (! function_exists('egypt_date')) {

    function egypt_date(string $dateOrDatetime): string

    {

        return EgyptTime::toDateString($dateOrDatetime);

    }

}



if (! function_exists('egypt_add_minutes_sql')) {

    function egypt_add_minutes_sql(int $minutes, $from = 'now'): string

    {

        return EgyptTime::addMinutesSql($minutes, $from === null || $from === '' ? 'now' : (string) $from);

    }

}



if (! function_exists('egypt_mysql_offset')) {

    function egypt_mysql_offset(): string

    {

        return EgyptTime::mysqlOffset();

    }

}



if (! function_exists('sync_mysql_egypt_timezone')) {

    function sync_mysql_egypt_timezone(): void

    {

        EgyptTime::syncMysqlTimezone();

    }

}


