import type { QSelectOption, QTableColumn } from "quasar";
import type { UserModuleAccess } from "src/modules/shared/models/user.models";

export type ModuleAccessPreset = 'admin' | 'supervisor' | 'employee' | 'none';
export type CompanyNames = 'Targo' | 'Solucom';

export interface PaidTimeOff {
    sick_hours: number;
    vacation_hours: number;
    banked_hours: number;
    last_updated?: string | null;
}

export class EmployeeProfile {
    first_name: string;
    last_name: string;
    supervisor_full_name: string;
    company_name: CompanyNames;
    job_title: string;
    email: string;
    phone_number: string;
    first_work_day: string;
    last_work_day?: string | null;
    external_payroll_id?: number;
    daily_expected_hours?: number;
    paid_time_off?: PaidTimeOff;
    residence: string;
    birth_date: string;
    is_supervisor: boolean;
    user_module_access: UserModuleAccess[];
    preset_id?: number | null;

    constructor() {
        this.first_name = '';
        this.last_name = '';
        this.supervisor_full_name = '';
        this.company_name = 'Targo';
        this.job_title = '';
        this.email = '';
        this.phone_number = '';
        this.first_work_day = '';
        this.last_work_day = null;
        this.residence = '';
        this.birth_date = '';
        this.is_supervisor = false;
        this.user_module_access = ['dashboard',];
    }
}

export interface EmployeeListFilters {
    search_bar_string: string;
    hide_inactive_users: boolean;
};

export const employee_list_columns: QTableColumn<EmployeeProfile>[] = [
    {
        name: 'first_name',
        label: 'timesheet_approvals.table.full_name',
        field: 'first_name',
        align: 'left',
        sortable: true,
    },
    {
        name: 'last_name',
        label: 'employee_list.table.last_name',
        field: 'last_name',
        align: 'left',
        sortable: true,
    },
    {
        name: 'email',
        label: 'employee_list.table.email',
        field: 'email',
        align: 'left',
        sortable: true,
    },
    {
        name: 'supervisor_full_name',
        label: 'employee_list.table.supervisor',
        field: 'supervisor_full_name',
        align: 'left',
        sortable: true,
    },
    {
        name: 'company_name',
        label: 'employee_list.table.company',
        field: 'company_name',
        align: 'left',
        sortable: true,
    },
    {
        name: 'phone_number',
        label: 'employee_list.table.phone_number',
        field: 'phone_number',
        align: 'left',
        sortable: true,
    },
    {
        name: 'job_title',
        label: 'employee_list.table.role',
        field: 'job_title',
        align: 'left',
    },
     {
        name: 'expected_daily_hours',
        label: 'employee_list.table.expected_daily_hours',
        field: 'daily_expected_hours',
        align: 'left',
    },
    {
        name: 'last_work_day',
        label: 'status',
        field: 'last_work_day',
        align: 'center',
        sortable: true,
        sort: (a: string | null, b: string | null) => {
            if (a === null && b === null) return 0;
            else if (a === null && b !== null) return 1;
            else return -1;
        },
    },
];

export const employee_access_options: QSelectOption<UserModuleAccess>[] = [
    { label: 'dashboard', value: 'dashboard' },
    { label: 'employee_list', value: 'employee_list' },
    { label: 'personal_profile', value: 'personal_profile' },
    { label: 'timesheets', value: 'timesheets' },
    { label: 'employee_management', value: 'employee_management' },
    { label: 'timesheets_approval', value: 'timesheets_approval' },
    { label: 'chatbot', value: 'chatbot' },
]

export const employee_access_presets: Record<ModuleAccessPreset, UserModuleAccess[]> = {
    'admin' : ['dashboard', 'employee_list', 'employee_management', 'personal_profile', 'timesheets', 'timesheets_approval'],
    'supervisor' : ['dashboard', 'employee_list', 'personal_profile', 'timesheets', 'timesheets_approval'],
    'employee' : ['dashboard', 'timesheets', 'personal_profile', 'employee_list'],
    'none' : [],
}

export const getEmployeeAccessOptionIcon = (module: UserModuleAccess): string => {
    switch (module) {
        case 'dashboard': return 'home';
        case 'employee_list' : return 'groups';
        case 'employee_management': return 'las la-user-edit';
        case 'personal_profile': return 'las la-id-card';
        case 'timesheets': return 'punch_clock';
        case 'timesheets_approval': return 'event_available';
        case 'chatbot': return 'las la-robot';
    }
}