using ERPCore.Domain.Enums;
using ERPCore.Dtos.Sales;

namespace ERPCore.Services.Interfaces;

public interface ISalesDomainService
{
    Task ValidateSalesHeaderAsync(
        int customerId,
        int warehouseId,
        int? cashierUserId,
        bool requireCashierUser,
        CancellationToken ct = default);

    Task ValidateSalesLineAsync(
        int headerWarehouseId,
        int lineItemId,
        int lineWarehouseId,
        decimal qty,
        decimal freeQty,
        int? parentLineId,
        CancellationToken ct = default);

    Task<SalesPriceResolution> ResolveLinePriceAsync(
        int itemId,
        int warehouseId,
        decimal? requestedUnitPrice,
        bool allowManualOverride,
        CancellationToken ct = default);

    SalesLineComputation ComputeLine(
        decimal qty,
        decimal freeQty,
        decimal unitPrice,
        SalesDiscountMode discountMode,
        decimal discountPct,
        decimal discountValue,
        decimal discountAmount,
        decimal taxPct,
        bool isFreeIssue);

    Task<bool> IsStockedItemAsync(int itemId, CancellationToken ct = default);
}

public sealed record SalesLineComputation(
    decimal Gross,
    decimal DiscountTotal,
    decimal NetUnitPrice,
    decimal LineTotal,
    decimal TaxAmount);
