/**
 * Tenant Settings Type Definitions
 *
 * Settings are tenant-specific configuration that comes from the backend
 * and is stored in IndexedDB for offline access.
 *
 * Each settings section is stored as a separate record with its own id.
 */

import { ISync } from './CalendarTypes';

/**
 * Workweek preset - defines which ISO weekdays to display
 * ISO: 1=Monday, 7=Sunday
 */
export interface IWorkweekPreset {
  id: string;
  workDays: number[];
  label: string;
  periodDays: number;  // Navigation step in days (1 = day, 7 = week)
}

/**
 * Workweek settings - stored as separate record
 */
export interface IWorkweekSettings extends ISync {
  id: 'workweek';
  presets: Record<string, IWorkweekPreset>;
  defaultPreset: string;
  firstDayOfWeek: number;  // ISO: 1=Monday
}

/**
 * Grid display settings - stored as separate record
 */
export interface IGridSettings extends ISync {
  id: 'grid';
  dayStartHour: number;
  dayEndHour: number;
  workStartHour: number;
  workEndHour: number;
  hourHeight: number;
  snapInterval: number;
}

/**
 * Time format settings - stored as separate record
 */
export interface ITimeFormatSettings extends ISync {
  id: 'timeFormat';
  timezone: string;
  locale: string;
  use24HourFormat: boolean;
}

/**
 * View settings - stored as separate record
 */
export interface IViewSettings extends ISync {
  id: 'views';
  availableViews: string[];
  defaultView: string;
}

/**
 * Union type for all tenant settings records
 */
export type TenantSetting = IWorkweekSettings | IGridSettings | ITimeFormatSettings | IViewSettings;

/**
 * Settings IDs as const for type safety
 */
export const SettingsIds = {
  WORKWEEK: 'workweek',
  GRID: 'grid',
  TIME_FORMAT: 'timeFormat',
  VIEWS: 'views'
} as const;
