import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model";
import { IEmployeeDocument } from "./Employees.Adapter.Mongoose";

export type FindEmployeesParams = {
    _id?: string;
    name?: string;
    companyId?: string;
    userId?: string;
};

export type PaginateEmployeesParams = FindEmployeesParams & {
    page: number;
    limit: number;
};

export type PaginateEmployeesResults = {
    data: IEmployee[];
    page: number;
    pages: number;
};

export enum EmployeeRoles {
    ADMIN = "admin",
    OWNER = "owner",
    EMPLOYEE = "employee",
}

export type CreateEmployeeParams = {
    companyId: string;
    userId: string;
    roles?: EmployeeRoles[];
    calendarColor?: string;
    limit?: number;
    hostOk?: boolean;
    sessionUser: string;
};

export type UpdateEmployeeParams = {
    id: string;
    calendarColor?: string;
    limit?: number;
    sessionUser: string;
};

export type UpdateEmployeeRolesParams = {
    employeeId: string;
    companyId: string;
    roles: EmployeeRoles[];
    calendarColor?: string;
    limit?: number;
    sessionUser: string;
};

export type FindEmployeesByIdParams = {
    id?: string;
};

export type ValidateEmployeeParams = {
    employeeId: string;
    sessionUser: string;
};

export type DeleteEmployeesByCompany = {
    companyId: string;
};

export type DeleteEmployeeParams = {
    employeeId: string;
};

export interface IEmployee {
    id?: string;
    companyId: string;
    userId: string;
    roles?: EmployeeRoles[];
    calendarColor?: string;
    limit?: number;
    guestOk?: boolean;
    hostOk?: boolean;
}

export interface CompanyEmployeesView {
    id: string;
    companyId: string;
    userId: string;
    firstName: string;
    lastName: string;
    fullName: string;
    avatar: string;
    email: string;
    roles: EmployeeRoles[];
    guestOk: boolean;
    hostOk: boolean;
    fullOk: boolean;
    calendarColor: string;
}

export interface IncompleteCollaboratorView {
    employeeId: string;
    companyId: string;
    companyName: string;
    name: string;
    missingServices: boolean;
    missingSchedules: boolean;
}

export interface IEmployeesAdapter {
    create(data: CreateEmployeeParams): Promise<IEmployee>;
    delete(id: string): Promise<void>;
    find(filters: FindEmployeesParams): Promise<IEmployee[]>;
    findOne(filters: FindEmployeesParams): Promise<IEmployeeDocument | null>;
    paginate(filters: PaginateEmployeesParams): Promise<PaginateEmployeesResults>;
}

export interface IEmployeesManager {
    employees: IEmployeesAdapter;
    checkRoleById(companyId: string, employeeId: string, role: EmployeeRoles): Promise<boolean>;
    createEmployee(data: CreateEmployeeParams): Promise<IEmployee>;
    updateEmployeeRoles(data: UpdateEmployeeRolesParams): Promise<void>;
    update(data: UpdateEmployeeParams): Promise<void>;
    findByCompanyId(data: FindEmployeesParams): Promise<CompanyEmployeesView[]>;
    findById(data: FindEmployeesByIdParams): Promise<CompanyEmployeesView>;
    textObjectFilter(data: FindEmployeesParams): Promise<TextObjectFilterResult[]>;
    deleteEmployeesByCompany(data: DeleteEmployeesByCompany): Promise<void>;
    deleteEmployee(data: DeleteEmployeeParams): Promise<void>;
    rejectGuest(data: ValidateEmployeeParams): Promise<void>;
    getIncompleteSetup(sessionUser: string): Promise<IncompleteCollaboratorView[]>;
}
