import { api } from "@/lib/api-client";
import type {
  AdmissionRegister, Admission,
  AdmissionRegisterCreateRequest, AdmissionCreateRequest,
} from "@/types/admission";
import type { PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export const admissionService = {
  async listRegisters(params?: PaginationParams): Promise<PaginatedResponse<AdmissionRegister>> {
    return api.get<PaginatedResponse<AdmissionRegister>>("/admission-registers", params as Record<string, string | number | boolean | undefined>);
  },

  async createRegister(data: AdmissionRegisterCreateRequest): Promise<AdmissionRegister> {
    return api.post<AdmissionRegister>("/admission-registers", data);
  },

  async updateRegister(id: number, data: Partial<AdmissionRegisterCreateRequest>): Promise<AdmissionRegister> {
    return api.patch<AdmissionRegister>(`/admission-registers/${id}`, data);
  },

  async confirmRegister(id: number): Promise<AdmissionRegister> {
    return api.post<AdmissionRegister>(`/admission-registers/${id}/confirm`);
  },

  async closeRegister(id: number): Promise<AdmissionRegister> {
    return api.post<AdmissionRegister>(`/admission-registers/${id}/close`);
  },

  async listAdmissions(params?: PaginationParams & { state?: string; register_id?: number; course_id?: number }): Promise<PaginatedResponse<Admission>> {
    return api.get<PaginatedResponse<Admission>>("/admissions", params as Record<string, string | number | boolean | undefined>);
  },

  async getAdmission(id: number): Promise<Admission> {
    return api.get<Admission>(`/admissions/${id}`);
  },

  async createAdmission(data: AdmissionCreateRequest): Promise<Admission> {
    return api.post<Admission>("/admissions", data);
  },

  async submitAdmission(id: number): Promise<Admission> {
    return api.post<Admission>(`/admissions/${id}/submit`);
  },

  async confirmAdmission(id: number): Promise<Admission> {
    return api.post<Admission>(`/admissions/${id}/confirm`);
  },

  async admitAdmission(id: number): Promise<Admission> {
    return api.post<Admission>(`/admissions/${id}/admit`);
  },

  async rejectAdmission(id: number): Promise<Admission> {
    return api.post<Admission>(`/admissions/${id}/reject`);
  },
};
