<?php

// General plugin logic, feature toggles, repository/service getters, plugin state, etc.

function easy_invoice_should_show_quote_adjust_field(): bool {
    return \EasyInvoice\Controllers\SettingsController::shouldShowQuoteAdjustField();
}
function easy_invoice_should_show_invoice_adjust_field(): bool {
    return \EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField();
}
function easy_invoice_get_quote_prefix(): string {
    return \EasyInvoice\Controllers\SettingsController::getQuotePrefix();
}
function easy_invoice_get_quote_starting_number(): int {
    return \EasyInvoice\Controllers\SettingsController::getQuoteStartingNumber();
}
function easy_invoice_get_quote_terms_conditions(): string {
    return \EasyInvoice\Controllers\SettingsController::getQuoteTermsConditions();
}
function easy_invoice_get_quote_footer_text(): string {
    return \EasyInvoice\Controllers\SettingsController::getQuoteFooterText();
}
function easy_invoice_should_show_quote_accept_button(): bool {
    return \EasyInvoice\Controllers\SettingsController::shouldShowQuoteAcceptButton();
}
function easy_invoice_get_quote_accept_action(): string {
    return \EasyInvoice\Controllers\SettingsController::getQuoteAcceptAction();
}
function easy_invoice_get_quote_accept_text(): string {
    return \EasyInvoice\Controllers\SettingsController::getQuoteAcceptText();
}
function easy_invoice_get_accepted_quote_message(): string {
    return \EasyInvoice\Controllers\SettingsController::getAcceptedQuoteMessage();
}
function easy_invoice_is_decline_reason_required(): bool {
    return \EasyInvoice\Controllers\SettingsController::isDeclineReasonRequired();
}
function easy_invoice_get_declined_quote_message(): string {
    return \EasyInvoice\Controllers\SettingsController::getDeclinedQuoteMessage();
}
function easy_invoice_get_invoice_prefix(): string {
    return \EasyInvoice\Controllers\SettingsController::getInvoicePrefix();
}
function easy_invoice_get_invoice_starting_number(): int {
    return \EasyInvoice\Controllers\SettingsController::getInvoiceStartingNumber();
}
function easy_invoice_get_invoice_terms_conditions(): string {
    return \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions();
}
function easy_invoice_get_invoice_footer_text(): string {
    return \EasyInvoice\Controllers\SettingsController::getInvoiceFooterText();
}

/**
 * Get invoice repository helper function.
 *
 * @since 1.0.0
 * @return \EasyInvoice\Interfaces\InvoiceRepositoryInterface
 */
function easy_invoice_get_repository() {
    return \EasyInvoice\Providers\InvoiceServiceProvider::getInvoiceRepository();
}

/**
 * Get client repository helper function.
 *
 * @since 1.0.0
 * @return \EasyInvoice\Interfaces\ClientRepositoryInterface
 */
function easy_invoice_get_client_repository() {
    return \EasyInvoice\Providers\ClientServiceProvider::getClientRepository();
}

/**
 * Get invoice item repository helper function.
 *
 * @since 1.0.0
 * @return \EasyInvoice\Interfaces\InvoiceItemRepositoryInterface
 */
function easy_invoice_get_invoice_item_repository() {
    return \EasyInvoice\Providers\InvoiceItemServiceProvider::getInvoiceItemRepository();
}

/**
 * Get invoice number service helper function.
 *
 * @since 1.0.0
 * @return \EasyInvoice\Services\InvoiceNumberService
 */
function easy_invoice_get_invoice_number_service() {
    $provider = new \EasyInvoice\Providers\InvoiceNumberServiceProvider();
    return $provider->getInvoiceNumberService();
}

/**
 * Get quote number service helper function.
 *
 * @since 1.0.0
 * @return \EasyInvoice\Services\QuoteNumberService
 */
function easy_invoice_get_quote_number_service() {
    return \EasyInvoice\Providers\QuoteNumberServiceProvider::getQuoteNumberServiceStatic();
}

/**
 * Check if Easy Invoice Pro is installed and active
 *
 * @since 1.0.0
 * @return bool
 */
function easy_invoice_has_pro(): bool {
    return class_exists('EasyInvoicePro');
}

/**
 * Convert various boolean values to a consistent boolean
 *
 * @since 1.0.0
 * @param mixed $value The value to convert to boolean
 * @return bool
 */
function easy_invoice_boolean($value): bool {
    return \EasyInvoice\Helpers\BooleanHelper::toBoolean($value);
}
function easy_invoice_str_replace($search, $replace, $subject, $count = null) {
    // Ensure $subject is not null
    $subject = $subject ?? '';
    
    if($count === null) {
        return str_replace($search, $replace, $subject);
    }
    return str_replace($search, $replace, $subject, $count);
}