import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index, ManyToOne, JoinColumn } from 'typeorm';
import { Order } from './order.entity';
import { User } from './user.entity';
import { Merchant } from './merchant.entity';
import { Room } from './room.entity';

@Entity('reviews')
export class Review {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @ManyToOne(() => Order)
  @JoinColumn({ name: 'order_id' })
  order: Order;

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

  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  user: User;

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

  @ManyToOne(() => Merchant)
  @JoinColumn({ name: 'merchant_id' })
  merchant: Merchant;

  @Index()
  @Column({ name: 'merchant_id', type: 'bigint', unsigned: true, comment: '商家ID' })
  merchantId: number;

  @ManyToOne(() => Room)
  @JoinColumn({ name: 'room_id' })
  room: Room;

  @Column({ name: 'room_id', type: 'bigint', unsigned: true, comment: '房型ID' })
  roomId: number;

  @Index()
  @Column({ type: 'tinyint', unsigned: true, comment: '评分(1-5)' })
  rating: number;

  @Column({ type: 'text', nullable: true, comment: '评价内容' })
  content: string;

  @Column({ type: 'json', nullable: true, comment: '评价图片列表' })
  images: string[];

  @Column({ name: 'merchant_reply', type: 'text', nullable: true, comment: '商家回复' })
  merchantReply: string;

  @Column({ name: 'replied_at', type: 'datetime', nullable: true, comment: '回复时间' })
  repliedAt: Date;

  @Column({ name: 'is_anonymous', type: 'boolean', default: false, comment: '是否匿名' })
  isAnonymous: boolean;

  @Column({ type: 'enum', enum: ['pending', 'visible', 'hidden'], default: 'pending', comment: '状态：pending-待审核, visible-已通过, hidden-已隐藏' })
  status: 'pending' | 'visible' | 'hidden';

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

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