import { api } from "@/lib/api-client";
import type { PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export interface ApprovalWorkflow {
  id: number;
  name: string;
  entity_id: number;
  entity_name: string;
  steps: { order: number; approver_id: number; approver_name: string }[];
  status: "active" | "draft";
  created_at: string;
}

export const approvalsService = {
  async list(params?: PaginationParams): Promise<PaginatedResponse<ApprovalWorkflow>> {
    return api.get<PaginatedResponse<ApprovalWorkflow>>("/approval-workflows", params as Record<string, string | number | boolean | undefined>);
  },

  async create(data: Partial<ApprovalWorkflow>): Promise<ApprovalWorkflow> {
    return api.post<ApprovalWorkflow>("/approval-workflows", data);
  },

  async update(id: number, data: Partial<ApprovalWorkflow>): Promise<ApprovalWorkflow> {
    return api.patch<ApprovalWorkflow>(`/approval-workflows/${id}`, data);
  },

  async delete(id: number): Promise<ApiSuccessResponse> {
    return api.delete<ApiSuccessResponse>(`/approval-workflows/${id}`);
  },
};
