package com.zt.plat.module.erp.api.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
@Schema(description = "管理后台 - 电子发票开具请求DTO")
public class ErpElectronicInvoiceSubmitReqDTO {

    @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED)
    private String id;

    @Schema(description = "开票日期；格式为YYYYMMDD（如20251106）", requiredMode = Schema.RequiredMode.REQUIRED)
    private String bill_date;

    @Schema(description = "是否暂估开票；长度1位字符")
    private String provi_estimate;

    @Schema(description = "发票抬头文本；长度25位字符")
    private String bill_text;

    @Schema(description = "最晚收款日期；格式为YYYYMMDD（如20251106）", requiredMode = Schema.RequiredMode.REQUIRED)
    private String bline_date;

    @Schema(description = "不开具电子发票；X-不开票；长度1位字符")
    private String no_invoicing;

    @Schema(description = "电子发票类型；no_invoicing为空时必填；05-普通发票，06-增值税专用发票；长度2位字符")
    private String invoice_type;

    @Schema(description = "电子发票备注；会带入到电子发票上；长度200位字符")
    private String invoice_note;

    @Schema(description = "红冲原因；no_invoicing为空且生成的是红字发票时必填；枚举值：开票有误、销货退回、服务终止、销售折让；长度20位字符")
    private String reversal_reason;

    @Schema(description = "发票行项目列表", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<InvoiceItem> item;

    @Schema(description = "发票条件明细列表", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<String> cond;

    @Schema(description = "发票附件列表")
    private List<InvoiceFileData> filedata;

    @Data
    @Schema(description = "发票行项目明细")
    public static class InvoiceItem {

        @Schema(description = "发票行号；从1开始顺序编号", requiredMode = Schema.RequiredMode.REQUIRED)
        private Integer data_index;

        @Schema(description = "参照类别；C-参照销售订单开票，J-根据交货单开票", requiredMode = Schema.RequiredMode.REQUIRED)
        private String ref_doc_ca;

        @Schema(description = "参照单号；长度10位字符", requiredMode = Schema.RequiredMode.REQUIRED)
        private String ref_doc;

        @Schema(description = "参照行号；长度6位数字", requiredMode = Schema.RequiredMode.REQUIRED)
        private String ref_item;

        @Schema(description = "开票数量；保留3位小数", requiredMode = Schema.RequiredMode.REQUIRED)
        private BigDecimal req_qty;

        @Schema(description = "规格型号；会带入到电子发票上；长度100位字符")
        private String model_note;
    }

    @Data
    @Schema(description = "发票条件明细")
    public static class InvoiceCond {

        @Schema(description = "发票行号；与item-data_index关联", requiredMode = Schema.RequiredMode.REQUIRED)
        private Integer data_index;

        @Schema(description = "条件类型；长度4位字符", requiredMode = Schema.RequiredMode.REQUIRED)
        private String cond_type;

        @Schema(description = "条件金额；保留4位小数", requiredMode = Schema.RequiredMode.REQUIRED)
        private BigDecimal cond_value;

        @Schema(description = "货币码；长度5位字符", requiredMode = Schema.RequiredMode.REQUIRED)
        private String cond_curr;

        @Schema(description = "条件单位；使用基本计量单位；长度3位字符", requiredMode = Schema.RequiredMode.REQUIRED)
        private String cond_d_unt;

        @Schema(description = "条件定价单位；固定值1；长度5位数字", requiredMode = Schema.RequiredMode.REQUIRED)
        private BigDecimal cond_p_unt;
    }

    @Data
    @Schema(description = "发票附件信息")
    public static class InvoiceFileData {

        @Schema(description = "文件名；必须带文件后缀名；长度200位字符", requiredMode = Schema.RequiredMode.REQUIRED)
        private String filename;

        @Schema(description = "文件内容；BASE64编码", requiredMode = Schema.RequiredMode.REQUIRED)
        private String filect;
    }
}
