// src/server/features/operations/db/daily_linen.table.ts
// Global daily linen usage table schema for storing consolidated linen items used per operational day

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

export const dailyLinenUsage = mysqlTable('daily_linen_usage', {
  id: varchar('id', { length: 36 }).primaryKey(),
  
  // Date of the operational day (unique) - YYYY-MM-DD format
  // FIXED: Changed from varchar to date with mode: string to match MySQL DATE type
  date: date('date', { mode: 'string' }).notNull().unique(),
  
  // Consolidated linen data for the day
  linenData: json('linen_data').$type<Array<{
    inventoryId: string;
    name: string;
    weight: number;
    quantity: number;
  }>>(),
  
  // System
  updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
}, (table) => ({
  dateIdx: uniqueIndex('daily_linen_usage_date_idx').on(table.date),
}));