package com.erp.finance.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 应付账款 - 采购订单审核通过后生成
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("fin_accounts_payable")
public class AccountsPayable {

    @TableId(type = IdType.AUTO)
    private Long id;

    /** 应付单号 */
    private String apNo;

    /** 关联采购单号 */
    private String purchaseOrderNo;

    /** 关联采购单ID */
    private Long purchaseOrderId;

    /** 供应商ID */
    private Long supplierId;

    /** 供应商名称 */
    private String supplierName;

    /** 应付金额（含税） */
    private BigDecimal totalAmount;

    /** 已入库金额 */
    private BigDecimal inboundAmount;

    /** 已付款金额 */
    private BigDecimal paidAmount;

    /** 未付款金额 */
    private BigDecimal unpaidAmount;

    /** 币种 */
    private String currency;

    /** 付款方式 */
    private String paymentMethod;

    /** 付款期限 */
    private LocalDate dueDate;

    /** 实际付款日期 */
    private LocalDate paidDate;

    /** 状态: pending/partial/paid/overdue/cancelled */
    private String status;

    /** 入库完成状态: pending/partial/completed */
    private String inboundStatus;

    /** 备注 */
    private String remark;

    /** 租户ID */
    private Long tenantId;

    /** 创建人 */
    private Long createBy;

    /** 创建时间 */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /** 更新人 */
    private Long updateBy;

    /** 更新时间 */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /** 逻辑删除 */
    @TableLogic
    private Integer deleted;

    // ============== 常量 ==============
    public static final String STATUS_PENDING = "pending";
    public static final String STATUS_PARTIAL = "partial";
    public static final String STATUS_PAID = "paid";
    public static final String STATUS_OVERDUE = "overdue";
    public static final String STATUS_CANCELLED = "cancelled";

    public static final String INBOUND_PENDING = "pending";
    public static final String INBOUND_PARTIAL = "partial";
    public static final String INBOUND_COMPLETED = "completed";
}
