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

import { cache } from "react";
import "server-only";

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 {
  id: number;
  to: string;
  cc: string;
  code: string;
  description: string;
  type: string;
  params: string;
  subjectCht: string;
  subjectEng: string;
  contentCht: string;
  contentEng: string;
}

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

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

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

export const fetchMailTemplates = cache(async () => {
  return serverFetchJson<MailTemplate[]>(`${BASE_API_URL}/mailTemplates`, {
    next: { tags: ["mailTemplates"] },
  });
});

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