import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index, ManyToOne, JoinColumn } from 'typeorm';
import { Merchant } from './merchant.entity';

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

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

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

  @Column({ length: 100, comment: '房型名称' })
  name: string;

  @Index()
  @Column({ type: 'enum', enum: ['hotel', 'homestay', 'apartment', 'hostel'], default: 'hotel', comment: '类型' })
  type: 'hotel' | 'homestay' | 'apartment' | 'hostel';

  @Column({ type: 'decimal', precision: 6, scale: 2, default: 0, comment: '面积(平方米)' })
  area: number;

  @Column({ name: 'bed_type', length: 50, default: '', comment: '床型' })
  bedType: string;

  @Column({ name: 'max_guests', type: 'tinyint', unsigned: true, default: 1, comment: '最多入住人数' })
  maxGuests: number;

  @Column({ length: 20, default: '', comment: '楼层' })
  floor: string;

  @Column({ type: 'json', nullable: true, comment: '设施列表' })
  facilities: string[];

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

  @Column({ name: 'cover_image', length: 500, default: '', comment: '封面图' })
  coverImage: string;

  @Index()
  @Column({ type: 'decimal', precision: 10, scale: 2, unsigned: true, default: 0, comment: '基础价格/晚' })
  price: number;

  @Column({ type: 'enum', enum: ['on_sale', 'off_sale'], default: 'on_sale', comment: '状态' })
  status: 'on_sale' | 'off_sale';

  @Index()
  @Column({ name: 'audit_status', type: 'enum', enum: ['pending', 'approved', 'rejected'], default: 'pending', comment: '审核状态' })
  auditStatus: 'pending' | 'approved' | 'rejected';

  @Column({ name: 'audit_reject_reason', length: 500, nullable: true, comment: '审核拒绝原因' })
  auditRejectReason?: string;

  @Index()
  @Column({ type: 'decimal', precision: 2, scale: 1, unsigned: true, default: 5.0, comment: '评分' })
  rating: number;

  @Column({ name: 'review_count', type: 'int', unsigned: true, default: 0, comment: '评价数' })
  reviewCount: number;

  @Column({ type: 'text', nullable: true, comment: '房源描述' })
  description: string;

  @Column({ name: 'cancel_policy', type: 'enum', enum: ['free', 'flexible', 'strict'], default: 'flexible', comment: '取消政策' })
  cancelPolicy: 'free' | 'flexible' | 'strict';

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

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