import { Entity, Column } from "typeorm";
import { BaseEntity } from "@/abstrClass/BaseEntity";
import dayjs from "dayjs";

@Entity("deceased")
export class Deceased extends BaseEntity {
  @Column("varchar", {
    name: "name",
    comment: "逝者姓名",
    length: 255,
    default: "",
  })
  name: string;

  @Column("varchar", {
    name: "id_number",
    comment: "证件号码",
    length: 50,
    default: "",
  })
  idNumber: string;

  @Column("varchar", {
    name: "gender",
    comment: "性别",
    length: 10,
    default: "男",
  })
  gender: string;

  @Column("int", {
    comment: "年龄",
    default: 0,
  })
  age: number;

  @Column("varchar", {
    name: "buyer",
    comment: "购买人",
    length: 255,
    default: "",
  })
  buyer: string;

  @Column("varchar", {
    name: "family_name",
    comment: "购买人",
    length: 255,
    default: "",
  })
  familyName: string;

  @Column("varchar", {
    name: "family_phone",
    comment: "购买人电话",
    length: 255,
    default: 0,
  })
  familyPhone: string;

  @Column({ comment: "所在省", default: "" })
  province: string; // 所在省
  @Column({ comment: "所在市", default: "" })
  city: string; // 所在市
  @Column({ comment: "所在区域", default: "" })
  area: string; // 所在区域
  @Column({ comment: "详细地址", default: "" })
  address: string; // 详细地址

  @Column("datetime", {
    name: "purchase_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");
      },
    },
  })
  purchaseDate: Date;

  @Column("varchar", {
    name: "handler",
    comment: "经办人",
    length: 255,
    default: "",
  })
  handler: string;

  @Column("decimal", {
    name: "sales_amount",
    comment: "销售金额",
    precision: 10,
    scale: 2,
    default: 0.0,
  })
  salesAmount: number;

  @Column("varchar", {
    name: "guide",
    comment: "引导员",
    length: 255,
    default: "",
  })
  guide: string;

  @Column("simple-array", {
    name: "service_items",
    comment: "服务项目列表",
  })
  serviceItems: number[];
}

export default Deceased;
