import { CrudClient } from "../infra/crud-client"
import { type ApiClientOptions } from "../infra/client"
import type { ApiPath, ApiRequestBody } from "../infra/types"

export const PAYMENT_MADE_ROUTES = {
    INDEX: "/api/payment-mades",
    BY_ID: "/api/payment-mades/{id}",
    ADD_ATTACHMENT: "/api/payment-mades/{id}/add-attachment",
    DELETE_ATTACHMENT: "/api/payment-mades/{id}/delete-attachment",
} as const satisfies Record<string, ApiPath>

export class PaymentMadesClient extends CrudClient<
    typeof PAYMENT_MADE_ROUTES.INDEX,
    typeof PAYMENT_MADE_ROUTES.BY_ID
> {
    constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
        super(baseUrl, defaultOptions, PAYMENT_MADE_ROUTES.INDEX, PAYMENT_MADE_ROUTES.BY_ID)
    }

    async addAttachment(id: string, payload: FormData) {
        return this.post(PAYMENT_MADE_ROUTES.ADD_ATTACHMENT, payload as never, { params: { id } } as never)
    }

    async deleteAttachment(id: string, payload: ApiRequestBody<typeof PAYMENT_MADE_ROUTES.DELETE_ATTACHMENT, "delete">) {
        return this.delete(PAYMENT_MADE_ROUTES.DELETE_ATTACHMENT, { params: { id }, body: payload } as never)
    }
}
