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

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

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

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

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

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

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

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

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

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

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

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

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

  @Column({ type: 'enum', enum: PaymentStatus, nullable: true, name: 'refund_status', comment: '退款状态' })
  refundStatus?: PaymentStatus;

  @Column({ type: 'varchar', length: 64, nullable: true, name: 'refund_transaction_id', comment: '微信退款流水号' })
  refundTransactionId?: string;

  @Column({ type: 'int', unsigned: true, nullable: true, name: 'refund_amount', comment: '退款金额（分）' })
  refundAmount?: number;

  @Column({ type: 'timestamp', nullable: true, name: 'refund_time', comment: '退款时间' })
  refundTime?: Date;
}