import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn, Index } from 'typeorm';
import { OrderMt } from './order.mt.entity';

@Entity('orders_refund_mt')
@Index(['tenantId'])
@Index(['tenantId', 'id'])
@Index(['tenantId', 'orderNo'])
@Index(['tenantId', 'refundOrderNo'])
export class OrderRefundMt {
  @PrimaryGeneratedColumn({ unsigned: true })
  id!: number;

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

  @Column({ name: 'order_no', type: 'varchar', length: 32, nullable: true, comment: '订单号' })
  orderNo!: string | null;

  @Column({ name: 'refund_order_no', type: 'varchar', length: 32, nullable: true, comment: '退款订单号' })
  refundOrderNo!: string | null;

  @Column({ name: 'refund_amount', type: 'decimal', precision: 10, scale: 2, nullable: true, comment: '退款金额' })
  refundAmount!: number | null;

  @Column({ name: 'state', type: 'int', default: 0, comment: '0未退款1退款中2退款成功3退款失败' })
  state!: number;

  @Column({ name: 'remark', type: 'varchar', length: 255, nullable: true, comment: '备注' })
  remark!: string | null;

  @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(() => OrderMt)
  @JoinColumn({ name: 'order_no', referencedColumnName: 'orderNo' })
  order!: OrderMt;
}