import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";

export interface MailSMTP {
    host: string;
    port: number;
    username: string;
    password: string;
}

export interface MailSetting {
    id: number;
    name: string;
    value: string;
    category: string;
    type: string;
}

export interface MailTemplate {
    cc?: string;
    bcc?: string;
    subject?: string;
    template?: string;
}

export const preloadMails = () => {
    fetchMailSetting();
    fetchMailTimesheetTemplate();
};

export const fetchMailSetting = cache(async () => {
    return serverFetchJson<MailSetting[]>(`${BASE_API_URL}/mails/setting`, {
        next: { tags: ["mailSetting"] },
    });
});

export const fetchMailTimesheetTemplate = cache(async () => {
    return serverFetchJson<MailSetting[]>(`${BASE_API_URL}/mails/timesheet-template`, {
        next: { tags: ["mailTimesheetTemplate"] },
    });
});
