import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn, ObjectLiteral } from 'typeorm';
import { UserEntity } from '../users/user.entity';
import { IdType } from './passenger.schema';

@Entity('passengers')
export class Passenger implements ObjectLiteral {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ name: 'user_id', type: 'integer', comment: '用户ID' })
  userId!: number;

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

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

  @Column({
    type: 'enum',
    enum: IdType,
    default: IdType.ID_CARD,
    comment: '证件类型'
  })
  idType!: IdType;

  @Column({ name: 'id_number', type: 'varchar', length: 30, comment: '证件号码' })
  idNumber!: string;

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

  @Column({ name: 'is_default', type: 'boolean', default: false, comment: '是否默认乘客' })
  isDefault!: boolean;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at', comment: '更新时间' })
  updatedAt!: Date;

  @Column({ name: 'created_by', type: 'integer', nullable: true, comment: '创建人ID' })
  createdBy?: number;

  @Column({ name: 'updated_by', type: 'integer', nullable: true, comment: '更新人ID' })
  updatedBy?: number;
}