import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "@/shared/services/axiosInstance";
import {
  ApplicationDto,
  ApplicationListResponse,
} from "@/user-management/dto/applications/applicationDto";
import { AxiosResponse } from "axios";

export interface CreateApplicationDto {
  key: string;
  name: {
    am: string;
    en: string;
  };
}

export interface UpdateApplicationDto {
  key?: string;
  name?: {
    am: string;
    en: string;
  };
}

export const applicationService = {
  getAll: (): Promise<AxiosResponse<ApplicationListResponse>> =>
    axiosInstance.get("/applications", { headers: withHeaders() }),

  getById: (id: string): Promise<AxiosResponse<ApplicationDto>> =>
    axiosInstance.get(`/applications/${id}`, { headers: withHeaders() }),

  create: (
    data: CreateApplicationDto,
  ): Promise<AxiosResponse<ApplicationDto>> =>
    axiosInstance.post("/applications", data, { headers: withHeaders() }),

  update: (
    id: string,
    data: UpdateApplicationDto,
  ): Promise<AxiosResponse<ApplicationDto>> =>
    axiosInstance.put(`/applications/${id}`, data, {
      headers: withHeaders(),
    }),

  delete: (id: string): Promise<AxiosResponse<void>> =>
    axiosInstance.delete(`/applications/${id}`, { headers: withHeaders() }),
};
