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

@Entity('room_expenses')
@Index(['importKey'], { unique: true })
export class RoomExpense {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'room_id' })
  roomId: number;

  @Column({ name: 'expense_type', type: 'varchar', length: 20 })
  expenseType: string;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  amount: number;

  @Column({ name: 'period_start', type: 'date' })
  periodStart: string;

  @Column({ name: 'period_end', type: 'date' })
  periodEnd: string;

  @Column({ type: 'text', nullable: true })
  description: string;

  @Column({ name: 'recorded_by', nullable: true })
  recordedBy: number;

  @Column({ name: 'import_key', type: 'varchar', length: 120, nullable: true, unique: true })
  importKey: string | null;

  @Column({ type: 'varchar', length: 20, default: 'active' })
  status: 'active' | 'archived';

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

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

}
