import type { TaskStatus, TaskStatusWrite } from './task-status'

export type StatusCategory = 'todo' | 'in_progress' | 'blocked' | 'review' | 'done'

export const STATUS_CATEGORY_LABEL: Record<StatusCategory, string> = {
    todo: 'À faire',
    in_progress: 'En cours',
    blocked: 'Bloqué',
    review: 'En validation',
    done: 'Terminé',
}

/** Palette canonique des catégories (couleurs « classiques »), indépendante des workflows. */
export const STATUS_CATEGORY_COLOR: Record<StatusCategory, string> = {
    todo: '#222783',
    in_progress: '#4A90D9',
    blocked: '#C62828',
    review: '#FF8F00',
    done: '#26A69A',
}

/** Renvoie '#1f2937' (foncé) ou '#ffffff' (blanc) selon la luminance du fond, pour rester lisible. */
export function contrastText(hex: string): string {
    const c = hex.replace('#', '')
    const r = parseInt(c.slice(0, 2), 16)
    const g = parseInt(c.slice(2, 4), 16)
    const b = parseInt(c.slice(4, 6), 16)
    const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255
    return lum > 0.6 ? '#1f2937' : '#ffffff'
}

export type Workflow = {
    id: number
    '@id'?: string
    name: string
    isDefault: boolean
    position: number
    statuses: TaskStatus[]
}

export type WorkflowWrite = {
    name: string
    isDefault: boolean
    position: number
    statuses?: TaskStatusWrite[]
}
