import { Document } from "mongoose";
import { TextObjectFilterResult } from "../TextObjectFilter.model";

export enum TemplateTypes {
    WAP_NEW_APPOINTMENT = "wap-new-appointment",
    WAP_REMINDER = "wap-reminder",
    EMAIL_NEW_APPOINTMENT = "email-new-appointment",
    EMAIL_REMINDER = "email-reminder",
}
export interface ITemplate {
    id?: string;
    _id?: string;
    companyId: string;
    name: string;
    code: string;
    type: TemplateTypes;
    template: string;
    createdAt: Date;
}

export interface ITemplateDocument extends Omit<ITemplate, "id" | "_id">, Document {
    _id: string;
}

export interface ITemplatesAdapter {
    create(data: Omit<CreateTemplateParams, "sessionUser">): Promise<ITemplate>;
    update(data: Omit<UpdateTemplateParams, "sessionUser">): Promise<ITemplate>;
    delete(data: Omit<DeleteTemplateParams, "sessionUser">): Promise<void>;
    find(filters: Omit<FindTemplatesParams, "sessionUser">): Promise<ITemplate[]>;
    findOne(filters: Omit<FindTemplatesParams, "sessionUser">): Promise<ITemplateDocument | null>;
    paginate(filters: PaginateTemplatesParams): Promise<PaginateTemplatesResults>;
}

export type FindTemplatesParams = {
    id?: string;
    companyId: string;
    code?: string;
    name?: string;
    type?: TemplateTypes;
    sessionUser: string;
};

export type PaginateTemplatesParams = FindTemplatesParams & {
    page: number;
    limit: number;
};

export type PaginateTemplatesResults = {
    data: ITemplate[];
    page: number;
    pages: number;
};

export type CreateTemplateParams = {
    companyId: string;
    name: string;
    code: string;
    type: TemplateTypes;
    template: string;
    sessionUser: string;
};

export type UpdateTemplateParams = {
    templateId: string;
    companyId: string;
    name: string;
    code: string;
    type: TemplateTypes;
    template: string;
    sessionUser: string;
};

export type SaveTemplateParams = {
    templateId?: string;
    companyId: string;
    name: string;
    code: string;
    type: TemplateTypes;
    template: string;
    sessionUser: string;
};

export type DeleteTemplateParams = {
    id: string;
    companyId: string;
    sessionUser: string;
};

export type GetDefaultTemplateParams = {
    type: TemplateTypes;
    companyId: string;
    sessionUser: string;
};

export type DeleteTemplatesByCompanyParams = {
    companyId: string;
};

export interface ITemplatesManager {
    templates: ITemplatesAdapter;
    deleteTemplatesByCompany(data: DeleteTemplatesByCompanyParams): Promise<void>;
    createTemplate(data: CreateTemplateParams): Promise<ITemplate>;
    updateTemplate(data: UpdateTemplateParams): Promise<ITemplate>;
    saveTemplate(data: SaveTemplateParams): Promise<ITemplate>;
    deleteTemplate(data: DeleteTemplateParams): Promise<void>;
    paginate(data: PaginateTemplatesParams): Promise<PaginateTemplatesResults>;
    getTemplate(data: FindTemplatesParams): Promise<ITemplate>;
    textObjectFilter(data: FindTemplatesParams): Promise<TextObjectFilterResult[]>;
    getDefaultTemplate(data: GetDefaultTemplateParams): Promise<string>;
}
