package com.erp.invoice.service;

import com.erp.invoice.dto.InvoiceRequest;
import com.erp.invoice.dto.InvoiceResponse;
import com.erp.invoice.entity.Invoice;
import com.baomidou.mybatisplus.extension.service.IService;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 发票服务接口
 */
public interface InvoiceService extends IService<Invoice> {
    
    // ==================== CRUD操作 ====================
    
    /**
     * 分页查询发票列表
     */
    Map<String, Object> listInvoices(Long tenantId, Integer status, Integer invoiceType,
                                       String keyword, LocalDate startDate, LocalDate endDate,
                                       Integer page, Integer size);
    
    /**
     * 获取发票详情
     */
    InvoiceResponse getInvoiceById(Long id);
    
    /**
     * 根据发票号获取发票
     */
    InvoiceResponse getInvoiceByInvoiceNo(String invoiceNo);
    
    // ==================== 发票申请 ====================
    
    /**
     * 创建发票申请
     */
    InvoiceResponse createInvoice(InvoiceRequest request, Long applicantId, String applicantName);
    
    /**
     * 更新发票申请（仅限待审核状态）
     */
    InvoiceResponse updateInvoice(Long id, InvoiceRequest request);
    
    /**
     * 删除发票申请（仅限待审核状态）
     */
    void deleteInvoice(Long id);
    
    // ==================== 发票审核 ====================
    
    /**
     * 审核发票申请
     */
    InvoiceResponse auditInvoice(Long id, Integer auditStatus, Long auditorId, String auditorName, String auditRemark);
    
    // ==================== 发票开具 ====================
    
    /**
     * 开具发票
     */
    InvoiceResponse issueInvoice(Long id, String invoiceNo, String invoiceCode, LocalDate invoiceDate,
                                  Long issuerId, String issuerName, String drawer, String reviewer, String payee);
    
    // ==================== 发票作废/红冲 ====================
    
    /**
     * 作废发票
     */
    InvoiceResponse voidInvoice(Long id, String reason, Long operatorId, String operatorName);
    
    /**
     * 红冲发票
     */
    InvoiceResponse reverseInvoice(Long id, String reason, Long operatorId, String operatorName);
    
    // ==================== 发票查询 ====================
    
    /**
     * 根据订单ID获取发票列表
     */
    List<InvoiceResponse> getInvoicesByOrderId(Long orderId);
    
    /**
     * 根据客户ID获取发票列表
     */
    List<InvoiceResponse> getInvoicesByCustomerId(Long customerId);
    
    /**
     * 获取租户已开具发票总金额
     */
    BigDecimal getIssuedAmountByTenant(Long tenantId);
    
    /**
     * 获取日期范围内发票数量
     */
    Integer countInvoicesByDateRange(Long tenantId, LocalDate startDate, LocalDate endDate);
    
    // ==================== 发票文件 ====================
    
    /**
     * 更新发票PDF路径
     */
    InvoiceResponse updatePdfPath(Long id, String pdfPath);
    
    /**
     * 更新发票图片路径
     */
    InvoiceResponse updateImagePath(Long id, String imagePath);
    
    // ==================== 发票明细 ====================
    
    /**
     * 添加发票明细
     */
    void addInvoiceItems(Long invoiceId, List<InvoiceRequest.InvoiceItemRequest> items);
    
    /**
     * 获取发票明细
     */
    List<InvoiceResponse.InvoiceItemResponse> getInvoiceItems(Long invoiceId);
    
    /**
     * 删除发票明细
     */
    void deleteInvoiceItems(Long invoiceId);
}
