import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { PaymentStatus } from './payment.types.js';

@Entity('payments')
export class PaymentEntity {
  @PrimaryGeneratedColumn({ comment: '支付记录ID' })
  id!: number;

  @Column({ type: 'int', unsigned: true, comment: '外部订单ID（用于与业务系统集成）' })
  externalOrderId!: number;

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

  @Column({ type: 'int', unsigned: true, comment: '支付金额（分）' })
  totalAmount!: number;

  @Column({ type: 'varchar', length: 128, comment: '支付描述' })
  description!: string;

  @Column({
    type: 'enum',
    enum: PaymentStatus,
    default: PaymentStatus.PENDING,
    comment: '支付状态'
  })
  paymentStatus!: PaymentStatus;

  @Column({ type: 'varchar', length: 64, nullable: true, comment: '微信支付交易ID' })
  wechatTransactionId?: string;

  @Column({ type: 'varchar', length: 64, nullable: true, comment: '商户订单号' })
  outTradeNo?: string;

  @Column({ type: 'varchar', length: 64, comment: '用户OpenID' })
  openid!: string;

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

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