package com.erp.order.settlement.service;

import com.erp.order.settlement.dto.*;
import com.erp.order.settlement.entity.OrderSettlement;
import com.erp.order.settlement.entity.SettlementPeriod;
import com.erp.order.settlement.entity.SettlementReport;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import com.erp.common.core.model.PageResponse;

/**
 * 订单结算服务接口
 */
public interface OrderSettlementService {

    // ==================== 订单结算基础操作 ====================

    /**
     * 创建订单结算记录
     */
    OrderSettlement createSettlement(OrderSettlement settlement);

    /**
     * 根据ID获取结算记录
     */
    OrderSettlement getSettlementById(Long id);

    /**
     * 根据结算单号获取
     */
    OrderSettlement getSettlementBySettlementNo(String settlementNo);

    /**
     * 根据订单ID获取结算记录
     */
    OrderSettlement getSettlementByOrderId(Long orderId);

    /**
     * 分页查询结算记录
     */
    PageResponse<SettlementDTO> querySettlements(SettlementQueryRequest request);

    /**
     * 更新结算记录
     */
    OrderSettlement updateSettlement(OrderSettlement settlement);

    /**
     * 批量更新结算状态
     */
    int batchUpdateStatus(List<Long> ids, String status);

    // ==================== 结算计算 ====================

    /**
     * 计算订单结算金额
     * 根据平台和店铺的佣金率计算实际结算金额
     */
    BigDecimal calculateSettlementAmount(Long orderId, BigDecimal commissionRate);

    /**
     * 批量计算结算
     * 对一批订单进行结算计算
     */
    List<OrderSettlement> batchCalculateSettlement(List<Long> orderIds, BigDecimal commissionRate);

    /**
     * 确认结算
     * 将待结算状态变更为已结算
     */
    boolean confirmSettlement(Long settlementId);

    /**
     * 批量确认结算
     */
    int batchConfirmSettlement(List<Long> settlementIds);

    /**
     * 冻结结算
     * 当发生退款或其他问题时冻结结算
     */
    boolean freezeSettlement(Long settlementId, String reason);

    // ==================== 结算周期管理 ====================

    /**
     * 创建结算周期
     */
    SettlementPeriod createSettlementPeriod(SettlementPeriod period);

    /**
     * 获取结算周期
     */
    SettlementPeriod getSettlementPeriodById(Long id);

    /**
     * 获取当前开放周期
     */
    SettlementPeriod getCurrentOpenPeriod(String periodType);

    /**
     * 关闭结算周期
     */
    boolean closeSettlementPeriod(Long periodId);

    /**
     * 结算周期内订单
     */
    int settlePeriodOrders(Long periodId);

    /**
     * 查询结算周期列表
     */
    List<SettlementPeriodDTO> querySettlementPeriods(SettlementQueryRequest request);

    // ==================== 统计报表 ====================

    /**
     * 获取结算统计数据
     */
    SettlementStatisticsDTO getStatistics(SettlementQueryRequest request);

    /**
     * 生成结算报表
     */
    SettlementReport generateReport(String reportType, Long shopId, String platform, LocalDate startDate, LocalDate endDate);

    /**
     * 获取结算报表
     */
    SettlementReport getReportById(Long id);

    /**
     * 查询结算报表列表
     */
    List<SettlementReport> queryReports(String reportType, LocalDate startDate, LocalDate endDate);

    /**
     * 确认结算报表
     */
    boolean confirmReport(Long reportId);

    // ==================== 店铺/平台维度统计 ====================

    /**
     * 获取店铺待结算金额
     */
    BigDecimal getShopPendingSettlementAmount(Long shopId);

    /**
     * 获取平台待结算金额
     */
    BigDecimal getPlatformPendingSettlementAmount(String platform);

    /**
     * 获取店铺结算汇总
     */
    SettlementStatisticsDTO.ShopStatistics getShopSettlementSummary(Long shopId, LocalDate startDate, LocalDate endDate);

    /**
     * 获取平台结算汇总
     */
    SettlementStatisticsDTO.PlatformStatistics getPlatformSettlementSummary(String platform, LocalDate startDate, LocalDate endDate);
}
