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

export const VENDOR_CREDIT_ROUTES = {
    INDEX: "/api/vendor-credits",
    BY_ID: "/api/vendor-credits/{id}",
    ADD_ATTACHMENT: "/api/vendor-credits/{id}/add-attachment",
    DELETE_ATTACHMENT: "/api/vendor-credits/{id}/delete-attachment",
    ADD_INTERNAL_NOTE: "/api/vendor-credits/{id}/add-internal-note",
    EDIT_INTERNAL_NOTE: "/api/vendor-credits/{id}/edit-internal-note",
    DELETE_INTERNAL_NOTE: "/api/vendor-credits/{id}/delete-internal-note",
} as const satisfies Record<string, ApiPath>

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

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

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

    async addInternalNote(id: string, payload: ApiRequestBody<typeof VENDOR_CREDIT_ROUTES.ADD_INTERNAL_NOTE, "post">) {
        return this.post(VENDOR_CREDIT_ROUTES.ADD_INTERNAL_NOTE, payload, { params: { id } } as never)
    }

    async editInternalNote(id: string, payload: ApiRequestBody<typeof VENDOR_CREDIT_ROUTES.EDIT_INTERNAL_NOTE, "delete">) {
        return this.delete(VENDOR_CREDIT_ROUTES.EDIT_INTERNAL_NOTE, { params: { id }, body: payload } as never)
    }

    async deleteInternalNote(id: string, payload: ApiRequestBody<typeof VENDOR_CREDIT_ROUTES.DELETE_INTERNAL_NOTE, "delete">) {
        return this.delete(VENDOR_CREDIT_ROUTES.DELETE_INTERNAL_NOTE, { params: { id }, body: payload } as never)
    }
}
