package com.awspaas.user.apps.donenow_ctt.service;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDate;

import java.util.List;
import java.util.Map;

/**
 * 发票处理和生成发票向导共用DTO
 */
public class InvoiceDealDto {

    // 页面参数：1-必填参数，2-可空参数
    /**
     * 处理活动（int）
     */
    private int processAction;

    /**
     * 发票模板（必填，int）
     */
    private int invoiceTemplateId;

    /**
     * 是否启用发票邮件服务（默认false，bool）
     */
    private boolean isInvoiceEmail = false;

    /**
     * 邮件信息模板ID（int）
     */
    private int emailTempId;

    /**
     * 发票日期（必填，DateTime）
     * 注：Java中用LocalDateTime对应日期时间类型，若仅需日期可改用LocalDate
     */
    private LocalDate invoiceDate;

    /**
     * 发票开始日期（可空，DateTime?）
     */
    private LocalDate dateRangeFrom;

    /**
     * 发票结束日期（可空，DateTime?）
     */
    private LocalDate dateRangeTo;

    /**
     * 订单号（可空，string）
     */
    private String purchaseOrderNo;

    /**
     * 发票备注（可空，string）
     */
    private String notes;

    /**
     * 支付条款ID（可空，int?）
     */
    private Integer paymentTermId;


    /**
     * 所有待处理发票的ID集合（必填，string）
     * 注：原类中与thisIds字段语义重复，建议后续业务中统一字段名
     */
    private String ids;

    /**
     * 向导专用：是否显示打印按钮（默认false，bool）
     */
    private boolean isShowPrint = false;

    /**
     * 向导专用：是否显示邮件按钮（默认false，bool）
     */
    private boolean isShowEmail = false;

    /**
     * 向导专用：是否关联QuickBooks（默认false，bool）
     */
    private boolean isQuickBooks = false;

    /**
     * 跳转预览界面使用的客户ID（待定，long）
     */
    private long accountId;

    /**
     * 本批次生成发票的批次ID（long）
     */
    private long invoiceBatch;

    /**
     * 存储发票编号信息（string）
     */
    private String invoiceNo;

    /**
     * 待处理发票的ID集合（与ids语义重复，string）
     */
    private String thisIds;

    /**
     * 支付条款名称（string）
     */
    private String paymentTermName;

    /**
     * 支付截止日期（string，建议后续改为LocalDate类型更规范）
     */
    private String paymentEndDate;

    private List<Map<String, Object>> UserDefinedFieldValue;

    // ==================== Getter 和 Setter 方法 ====================
    public int getProcessAction() {
        return processAction;
    }

    public void setProcessAction(int processAction) {
        this.processAction = processAction;
    }

    public int getInvoiceTemplateId() {
        return invoiceTemplateId;
    }

    public void setInvoiceTemplateId(int invoiceTemplateId) {
        this.invoiceTemplateId = invoiceTemplateId;
    }

    public boolean isInvoiceEmail() {
        return isInvoiceEmail;
    }

    public void setInvoiceEmail(boolean invoiceEmail) {
        isInvoiceEmail = invoiceEmail;
    }

    public int getEmailTempId() {
        return emailTempId;
    }

    public void setEmailTempId(int emailTempId) {
        this.emailTempId = emailTempId;
    }

    public LocalDate getInvoiceDate() {
        if (invoiceDate == null)
            invoiceDate = LocalDate.now();
        return invoiceDate;
    }

    public void setInvoiceDate(LocalDate invoiceDate) {
        this.invoiceDate = invoiceDate;
    }

    public LocalDate getDateRangeFrom() {
        return this.dateRangeFrom;
    }

    public void setDateRangeFrom(LocalDate dateRangeFrom) {
        this.dateRangeFrom = dateRangeFrom;
    }

    public void setDateRangeFromStr(String dateRangeFrom) {
        try {
            if (StringUtils.isNotBlank(dateRangeFrom)) {
                dateRangeFrom = dateRangeFrom.substring(0, 10);
                this.dateRangeFrom = LocalDate.parse(dateRangeFrom);
            }

        } catch (Exception e) {
            e.printStackTrace();
            this.dateRangeFrom = null;
        }
    }

    public LocalDate getDateRangeTo() {
        return dateRangeTo;
    }


    public void setDateRangeTo(LocalDate dateRangeTo) {
        this.dateRangeTo = dateRangeTo;
    }

    public void setDateRangeToStr(String dateRangeTo) {
        try {
            if (StringUtils.isNotBlank(dateRangeTo)) {
                dateRangeTo = dateRangeTo.substring(0, 10);
                this.dateRangeTo = LocalDate.parse(dateRangeTo);
            }
        } catch (Exception e) {
            e.printStackTrace();
            this.dateRangeTo = null;
        }
    }

    public String getPurchaseOrderNo() {
        return purchaseOrderNo;
    }

    public void setPurchaseOrderNo(String purchaseOrderNo) {
        this.purchaseOrderNo = purchaseOrderNo;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Integer getPaymentTermId() {
        return paymentTermId;
    }

    public void setPaymentTermId(Integer paymentTermId) {
        this.paymentTermId = paymentTermId;
    }

    public String getIds() {
        return ids;
    }

    public void setIds(String ids) {
        this.ids = ids;
    }

    public boolean isShowPrint() {
        return isShowPrint;
    }

    public void setShowPrint(boolean showPrint) {
        isShowPrint = showPrint;
    }

    public boolean isShowEmail() {
        return isShowEmail;
    }

    public void setShowEmail(boolean showEmail) {
        isShowEmail = showEmail;
    }

    public boolean isQuickBooks() {
        return isQuickBooks;
    }

    public void setQuickBooks(boolean quickBooks) {
        isQuickBooks = quickBooks;
    }

    public long getAccountId() {
        return accountId;
    }

    public void setAccountId(long accountId) {
        this.accountId = accountId;
    }

    public long getInvoiceBatch() {
        return invoiceBatch;
    }

    public void setInvoiceBatch(long invoiceBatch) {
        this.invoiceBatch = invoiceBatch;
    }

    public String getInvoiceNo() {
        return invoiceNo;
    }

    public void setInvoiceNo(String invoiceNo) {
        this.invoiceNo = invoiceNo;
    }

    public String getThisIds() {
        return thisIds;
    }

    public void setThisIds(String thisIds) {
        this.thisIds = thisIds;
    }

    public String getPaymentTermName() {
        return paymentTermName;
    }

    public void setPaymentTermName(String paymentTermName) {
        this.paymentTermName = paymentTermName;
    }

    public String getPaymentEndDate() {
        return paymentEndDate;
    }

    public void setPaymentEndDate(String paymentEndDate) {
        this.paymentEndDate = paymentEndDate;
    }

    /**
     * 获取用户自定义字段的值
     * @return
     */
    public List<Map<String, Object>> getUserDefinedFieldValue() {
        return UserDefinedFieldValue;
    }

    /**
     * 设置用户自定义字段的值
     * @param userDefinedFieldValue
     */
    public void setUserDefinedFieldValue(List<Map<String, Object>> userDefinedFieldValue) {
        UserDefinedFieldValue = userDefinedFieldValue;
    }
}