<?php

if ( !defined( 'ABSPATH' ) ) {

    exit;
}

if ( !class_exists( 'Pricely_Product_Prices_Types' ) ) {

    require_once dirname( __FILE__ ) . '/product-price-types-sale.php';

    class Pricely_Product_Prices_Types {

        private static $instance;

        public static function get_instance(): self {

            if ( !self::$instance ) {

                self::$instance = new self();
            }

            return self::$instance;
        }

        public function get_prices( $prices_args, $data ) {

            $prices = array();

            if ( 'sale' == $prices_args[ 'mode' ] ) {

                $sale_prices = new Pricely_Product_Prices_Type_Sale();

                $prices = $sale_prices->get_prices( $prices, $prices_args, $data );
            }

            $filter_key = 'product-pricing_calculate-product-' . $prices_args[ 'mode' ] . '-prices';

            if ( has_filter( 'pricely_' . $filter_key ) ) {

                $prices = apply_filters( 'pricely_' . $filter_key, $prices, $prices_args, $data );
            }

            return $prices;
        }

        public function get_based_on_amount( $based_on, $data ) {

            if ( isset( $data[ 'wc' ][ 'product' ][ 'regular_price' ] ) ) {

                $amount = $data[ 'wc' ][ 'product' ][ 'regular_price' ];

                if ( is_numeric( $amount ) ) {

                    return $amount;
                }
            }

            $filter_key = 'product-pricing_get-' . $based_on . '-based-on-amount';

            if ( has_filter( 'pricely_' . $filter_key ) ) {

                return apply_filters( 'pricely_' . $filter_key, 0, $data );
            }

            return 0;
        }

    }

}
