import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn, Index } from 'typeorm';
import { Settlement } from './settlement.entity';

@Entity('settlement_items')
@Index('idx_settlement_id', ['settlementId'])
@Index('idx_order_id', ['orderId'])
export class SettlementItem {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true, comment: '结算明细ID' })
  id: number;

  @ManyToOne(() => Settlement, s => s.items)
  @JoinColumn({ name: 'settlement_id' })
  settlement: Settlement;

  @Column({ type: 'bigint', unsigned: true, name: 'settlement_id', comment: '结算单ID' })
  settlementId: number;

  @Column({ type: 'bigint', unsigned: true, name: 'order_id', comment: '订单ID' })
  orderId: number;

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

  @Column({ type: 'decimal', precision: 12, scale: 2, name: 'order_amount', comment: '订单金额' })
  orderAmount: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, name: 'service_fee', comment: '服务费' })
  serviceFee: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, name: 'settlement_amount', comment: '结算金额' })
  settlementAmount: number;

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