import { Entity, Column, OneToOne, JoinColumn } from "typeorm";
import { BaseEntity } from "@/abstrClass/BaseEntity";
import DeceasedRetail from "./DeceasedRetail";
import dayjs from "dayjs";

@Entity("cancel_retail")
export class CancelRetail extends BaseEntity {
  @Column("int", {
    name: "deceasedRetail_id",
    comment: "销售单ID",
    default: 0,
  })
  deceasedRetailId: number;

  @Column("int", {
    name: "checkoutRetail_id",
    comment: "服务销售单ID",
    default: 0,
  })
  checkoutRetailId: number;

  @Column("varchar", {
    name: "cancel_person",
    length: 100,
    comment: "作废申请人",
    default: "",
  })
  cancelPerson: string;

  @Column("datetime", {
    name: "cancel_date",
    comment: "作废日期",
    default: () => "CURRENT_TIMESTAMP", // 默认值为当前时间
    transformer: {
      to(value: Date) {
        return value;
      },
      from(value) {
        return dayjs(new Date(value)).format("YYYY-MM-DD HH:mm:ss");
      },
    },
  })
  cancelDate: Date;

  @Column("varchar", {
    name: "cancel_reason",
    comment: "作废原因",
    default: "",
  })
  cancelReason: string;

  @Column("int", {
    name: "examine_state",
    comment: "审核状态 (0: 未审核, 1: 已审核， 2: 拒绝)",
    default: 0,
  })
  examineState: number;

  @Column("int", {
    name: "cancel_type",
    comment: "作废类型，0结账处理、1零售结算",
    default: 0,
  })
  cancelType: number;

  @Column("varchar", {
    name: "examine_pserson",
    comment: "审核人",
    default: "",
  })
  examinePserson: string;

  @Column("datetime", {
    name: "examine_date",
    comment: "审核时间",
    nullable: true, // 允许为空
    transformer: {
      to(value: Date) {
        return value;
      },
      from(value) {
        return dayjs(new Date(value)).format("YYYY-MM-DD HH:mm:ss");
      },
    },
  })
  examineDate: Date;
}

export default CancelRetail;
