namespace TakeoutSaaS.TenantApi.Contracts.Finance;

/// <summary>
/// 财务概览查询请求。
/// </summary>
public sealed class FinanceOverviewDashboardRequest
{
    /// <summary>
    /// 维度（tenant/store）。
    /// </summary>
    public string? Dimension { get; set; }

    /// <summary>
    /// 门店 ID（门店维度必填）。
    /// </summary>
    public string? StoreId { get; set; }
}

/// <summary>
/// 财务概览指标卡响应。
/// </summary>
public sealed class FinanceOverviewKpiCardResponse
{
    /// <summary>
    /// 指标值。
    /// </summary>
    public decimal Amount { get; set; }

    /// <summary>
    /// 对比值。
    /// </summary>
    public decimal CompareAmount { get; set; }

    /// <summary>
    /// 变化率（%）。
    /// </summary>
    public decimal ChangeRate { get; set; }

    /// <summary>
    /// 趋势（up/down/flat）。
    /// </summary>
    public string Trend { get; set; } = "flat";

    /// <summary>
    /// 对比文案。
    /// </summary>
    public string CompareLabel { get; set; } = "较昨日";
}

/// <summary>
/// 收入趋势点响应。
/// </summary>
public sealed class FinanceOverviewIncomeTrendPointResponse
{
    /// <summary>
    /// 日期（yyyy-MM-dd）。
    /// </summary>
    public string Date { get; set; } = string.Empty;

    /// <summary>
    /// 轴标签（MM/dd）。
    /// </summary>
    public string DateLabel { get; set; } = string.Empty;

    /// <summary>
    /// 实收金额。
    /// </summary>
    public decimal Amount { get; set; }
}

/// <summary>
/// 收入趋势响应。
/// </summary>
public sealed class FinanceOverviewIncomeTrendResponse
{
    /// <summary>
    /// 近 7 天。
    /// </summary>
    public List<FinanceOverviewIncomeTrendPointResponse> Last7Days { get; set; } = [];

    /// <summary>
    /// 近 30 天。
    /// </summary>
    public List<FinanceOverviewIncomeTrendPointResponse> Last30Days { get; set; } = [];
}

/// <summary>
/// 利润趋势点响应。
/// </summary>
public sealed class FinanceOverviewProfitTrendPointResponse
{
    /// <summary>
    /// 日期（yyyy-MM-dd）。
    /// </summary>
    public string Date { get; set; } = string.Empty;

    /// <summary>
    /// 轴标签（MM/dd）。
    /// </summary>
    public string DateLabel { get; set; } = string.Empty;

    /// <summary>
    /// 营收。
    /// </summary>
    public decimal RevenueAmount { get; set; }

    /// <summary>
    /// 成本。
    /// </summary>
    public decimal CostAmount { get; set; }

    /// <summary>
    /// 净利润。
    /// </summary>
    public decimal NetProfitAmount { get; set; }
}

/// <summary>
/// 利润趋势响应。
/// </summary>
public sealed class FinanceOverviewProfitTrendResponse
{
    /// <summary>
    /// 近 7 天。
    /// </summary>
    public List<FinanceOverviewProfitTrendPointResponse> Last7Days { get; set; } = [];

    /// <summary>
    /// 近 30 天。
    /// </summary>
    public List<FinanceOverviewProfitTrendPointResponse> Last30Days { get; set; } = [];
}

/// <summary>
/// 收入构成项响应。
/// </summary>
public sealed class FinanceOverviewIncomeCompositionItemResponse
{
    /// <summary>
    /// 渠道编码。
    /// </summary>
    public string Channel { get; set; } = string.Empty;

    /// <summary>
    /// 渠道文案。
    /// </summary>
    public string ChannelText { get; set; } = string.Empty;

    /// <summary>
    /// 金额。
    /// </summary>
    public decimal Amount { get; set; }

    /// <summary>
    /// 占比（%）。
    /// </summary>
    public decimal Percentage { get; set; }
}

/// <summary>
/// 收入构成响应。
/// </summary>
public sealed class FinanceOverviewIncomeCompositionResponse
{
    /// <summary>
    /// 总实收。
    /// </summary>
    public decimal TotalAmount { get; set; }

    /// <summary>
    /// 构成项。
    /// </summary>
    public List<FinanceOverviewIncomeCompositionItemResponse> Items { get; set; } = [];
}

/// <summary>
/// 成本构成项响应。
/// </summary>
public sealed class FinanceOverviewCostCompositionItemResponse
{
    /// <summary>
    /// 分类编码。
    /// </summary>
    public string Category { get; set; } = string.Empty;

    /// <summary>
    /// 分类文案。
    /// </summary>
    public string CategoryText { get; set; } = string.Empty;

    /// <summary>
    /// 金额。
    /// </summary>
    public decimal Amount { get; set; }

    /// <summary>
    /// 占比（%）。
    /// </summary>
    public decimal Percentage { get; set; }
}

/// <summary>
/// 成本构成响应。
/// </summary>
public sealed class FinanceOverviewCostCompositionResponse
{
    /// <summary>
    /// 总成本。
    /// </summary>
    public decimal TotalAmount { get; set; }

    /// <summary>
    /// 构成项。
    /// </summary>
    public List<FinanceOverviewCostCompositionItemResponse> Items { get; set; } = [];
}

/// <summary>
/// TOP 商品项响应。
/// </summary>
public sealed class FinanceOverviewTopProductItemResponse
{
    /// <summary>
    /// 排名。
    /// </summary>
    public int Rank { get; set; }

    /// <summary>
    /// 商品名称。
    /// </summary>
    public string ProductName { get; set; } = string.Empty;

    /// <summary>
    /// 销量。
    /// </summary>
    public int SalesQuantity { get; set; }

    /// <summary>
    /// 营收金额。
    /// </summary>
    public decimal RevenueAmount { get; set; }

    /// <summary>
    /// 占比（%）。
    /// </summary>
    public decimal Percentage { get; set; }
}

/// <summary>
/// TOP 商品响应。
/// </summary>
public sealed class FinanceOverviewTopProductResponse
{
    /// <summary>
    /// 周期天数。
    /// </summary>
    public int PeriodDays { get; set; } = 30;

    /// <summary>
    /// 排行项。
    /// </summary>
    public List<FinanceOverviewTopProductItemResponse> Items { get; set; } = [];
}

/// <summary>
/// 财务概览响应。
/// </summary>
public sealed class FinanceOverviewDashboardResponse
{
    /// <summary>
    /// 维度编码。
    /// </summary>
    public string Dimension { get; set; } = "tenant";

    /// <summary>
    /// 门店标识。
    /// </summary>
    public string? StoreId { get; set; }

    /// <summary>
    /// 今日营业额卡片。
    /// </summary>
    public FinanceOverviewKpiCardResponse TodayRevenue { get; set; } = new();

    /// <summary>
    /// 实收卡片。
    /// </summary>
    public FinanceOverviewKpiCardResponse ActualReceived { get; set; } = new();

    /// <summary>
    /// 退款卡片。
    /// </summary>
    public FinanceOverviewKpiCardResponse RefundAmount { get; set; } = new();

    /// <summary>
    /// 净收入卡片。
    /// </summary>
    public FinanceOverviewKpiCardResponse NetIncome { get; set; } = new();

    /// <summary>
    /// 可提现余额卡片。
    /// </summary>
    public FinanceOverviewKpiCardResponse WithdrawableBalance { get; set; } = new();

    /// <summary>
    /// 收入趋势。
    /// </summary>
    public FinanceOverviewIncomeTrendResponse IncomeTrend { get; set; } = new();

    /// <summary>
    /// 利润趋势。
    /// </summary>
    public FinanceOverviewProfitTrendResponse ProfitTrend { get; set; } = new();

    /// <summary>
    /// 收入构成。
    /// </summary>
    public FinanceOverviewIncomeCompositionResponse IncomeComposition { get; set; } = new();

    /// <summary>
    /// 成本构成。
    /// </summary>
    public FinanceOverviewCostCompositionResponse CostComposition { get; set; } = new();

    /// <summary>
    /// TOP 商品排行。
    /// </summary>
    public FinanceOverviewTopProductResponse TopProducts { get; set; } = new();
}
