// src/server/features/operations/db/daily_checkins.table.ts
// Daily check-in table schema for guest check-in operations with cleaning status and linen tracking

import { mysqlTable, varchar, int, timestamp, boolean, json, date, uniqueIndex } from 'drizzle-orm/mysql-core';

export const dailyCheckins = mysqlTable('daily_checkins', {
  id: varchar('id', { length: 36 }).primaryKey(),
  
  // Room Reference & Snapshot
  roomId: varchar('room_id', { length: 10 }).notNull(), 
  roomType: varchar('room_type', { length: 100 }).notNull(),   
  
  // Operation Data
  // FIXED: Changed from varchar to date with mode: string
  date: date('date', { mode: 'string' }).notNull(), 
  
  isOccupied: boolean('is_occupied').notNull().default(false), 
  isPermanent: boolean('is_permanent').notNull().default(false), 
  bedsCount: int('beds_count').notNull().default(0), 

  // Check-in / Check-out
  isCheckin: boolean('is_checkin').notNull().default(false),
  isCheckout: boolean('is_checkout').notNull().default(false),
  
  // Service Data
  isCleaned: boolean('is_cleaned').notNull().default(false), 
  cleanerName: varchar('cleaner_name', { length: 255 }),
  isLinenChanged: boolean('is_linen_changed').notNull().default(false),
  comment: varchar('comment', { length: 500 }),
  
  // Laundry Data
  linenData: json('linen_data'), 
  isDispatched: boolean('is_dispatched').notNull().default(false), 
  
  // System
  createdAt: timestamp('created_at').notNull().defaultNow(),
  updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
  // archivedAt removed - snapshots use hard delete instead
}, (table) => ({
  unq: uniqueIndex('date_room_idx').on(table.date, table.roomId),
}));