import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { UserEntityMt } from '@d8d/user-module-mt';
import { AreaEntityMt } from '@d8d/geo-areas-mt';

@Entity('delivery_addresses_mt')
export class DeliveryAddressMt {
  @PrimaryGeneratedColumn({ unsigned: true })
  id!: number;

  @Column({ name: 'tenant_id', type: 'int', unsigned: true, comment: '租户ID' })
  tenantId!: number;

  @Column({ name: 'user_id', type: 'int', unsigned: true, comment: '用户id' })
  userId!: number;

  @Column({ name: 'name', type: 'varchar', length: 255, comment: '姓名' })
  name!: string;

  @Column({ name: 'phone', type: 'varchar', length: 255, comment: '手机号' })
  phone!: string;

  @Column({ name: 'address', type: 'varchar', length: 255, comment: '详细地址' })
  address!: string;

  @Column({ name: 'receiver_province', type: 'bigint', unsigned: true, default: 0, comment: '省' })
  receiverProvince!: number;

  @Column({ name: 'receiver_city', type: 'bigint', unsigned: true, default: 0, comment: '市' })
  receiverCity!: number;

  @Column({ name: 'receiver_district', type: 'bigint', unsigned: true, default: 0, comment: '区' })
  receiverDistrict!: number;

  @Column({ name: 'receiver_town', type: 'bigint', unsigned: true, default: 0, comment: '街道' })
  receiverTown!: number;

  @Column({ name: 'state', type: 'int', unsigned: true, default: 1, comment: '是否可用1正常2禁用3删除（不显示）' })
  state!: number;

  @Column({ name: 'is_default', type: 'int', unsigned: true, default: 0, comment: '是否常用1是 2否' })
  isDefault!: number;

  @Column({ name: 'created_by', type: 'int', unsigned: true, nullable: true, comment: '创建用户ID' })
  createdBy!: number | null;

  @Column({ name: 'updated_by', type: 'int', unsigned: true, nullable: true, comment: '更新用户ID' })
  updatedBy!: number | null;

  @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  updatedAt!: Date;

  @ManyToOne(() => UserEntityMt)
  @JoinColumn({ name: 'user_id', referencedColumnName: 'id' })
  user!: UserEntityMt;

  @ManyToOne(() => AreaEntityMt)
  @JoinColumn({ name: 'receiver_province', referencedColumnName: 'id' })
  province!: AreaEntityMt;

  @ManyToOne(() => AreaEntityMt)
  @JoinColumn({ name: 'receiver_city', referencedColumnName: 'id' })
  city!: AreaEntityMt;

  @ManyToOne(() => AreaEntityMt)
  @JoinColumn({ name: 'receiver_district', referencedColumnName: 'id' })
  district!: AreaEntityMt;

  @ManyToOne(() => AreaEntityMt)
  @JoinColumn({ name: 'receiver_town', referencedColumnName: 'id' })
  town!: AreaEntityMt;
}