<?php
defined( 'ABSPATH' ) || exit;

class Woocom_Pay_Order_Status {

	public static function init(): void {
		add_action( 'init', [ __CLASS__, 'register_statuses' ] );
		add_filter( 'wc_order_statuses', [ __CLASS__, 'add_to_wc_statuses' ] );
		add_filter( 'woocommerce_order_is_paid_statuses', [ __CLASS__, 'paid_statuses' ] );
		add_filter( 'woocommerce_reports_order_statuses', [ __CLASS__, 'report_statuses' ] );
	}

	public static function statuses(): array {
		return [
			'wc-awaiting-pay'   => __( 'Awaiting Payment', 'woocom-pay' ),
			'wc-pay-submitted'  => __( 'Payment Submitted', 'woocom-pay' ),
			'wc-pay-verified'   => __( 'Payment Verified', 'woocom-pay' ),
			'wc-bal-pending'    => __( 'Balance Pending', 'woocom-pay' ),
			'wc-bal-submitted'  => __( 'Balance Submitted', 'woocom-pay' ),
			'wc-pay-rejected'   => __( 'Payment Rejected', 'woocom-pay' ),
		];
	}

	public static function register_statuses(): void {
		foreach ( self::statuses() as $slug => $label ) {
			register_post_status( $slug, [
				'label'                     => $label,
				'public'                    => true,
				'exclude_from_search'       => false,
				'show_in_admin_all_list'    => true,
				'show_in_admin_status_list' => true,
				/* translators: %s: count */
				'label_count'               => _n_noop( $label . ' <span class="count">(%s)</span>', $label . ' <span class="count">(%s)</span>', 'woocom-pay' ),
			] );
		}
	}

	public static function add_to_wc_statuses( array $statuses ): array {
		return array_merge( $statuses, self::statuses() );
	}

	public static function paid_statuses( array $statuses ): array {
		return array_merge( $statuses, [ 'pay-verified', 'bal-pending', 'bal-submitted' ] );
	}

	public static function report_statuses( array $statuses ): array {
		return array_merge( $statuses, [ 'pay-verified', 'bal-pending', 'bal-submitted' ] );
	}
}
