import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { Agent } from '../agent/agent.entity';

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

  @Column({ name: 'agent_id', type: 'int', unsigned: true, nullable: true, comment: '代理商ID' })
  agentId!: number | null;

  @Column({ name: 'card_type', type: 'smallint', unsigned: true, comment: '1盛京通卡 2通用联名电子卡' })
  cardType!: number;

  @Column({ name: 'card_no', type: 'varchar', length: 20, unique: true, comment: '卡号' })
  cardNo!: string;

  @Column({ name: 'password', type: 'varchar', length: 255, comment: '密码' })
  password!: string;

  @Column({ name: 'state', type: 'smallint', unsigned: true, default: 1, comment: '状态 1绑定 2解绑 通用联名电子卡不可解绑' })
  state!: number;

  @Column({ name: 'face_value', type: 'decimal', precision: 10, scale: 2, unsigned: true, default: 0.00, comment: '面值' })
  faceValue!: number;

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

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

  @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;

  @ManyToOne(() => Agent, { nullable: true })
  @JoinColumn({ name: 'agent_id', referencedColumnName: 'id' })
  agent!: Agent | null;
}