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

export const VENDOR_ROUTES = {
    INDEX: "/api/vendors",
    BY_ID: "/api/vendors/{id}",
    TOGGLE_STATUS: "/api/toggle-vendor-status",
    CREATE_ADDRESS: "/api/create-vendor-address",
    ADDRESS_BY_ID: "/api/vendor-address/{id}",
} as const satisfies Record<string, ApiPath>

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

    async getById(id: string) {
        return this.show(id)
    }

    async toggleStatus(payload: ApiRequestBody<typeof VENDOR_ROUTES.TOGGLE_STATUS, "post">) {
        return this.post(VENDOR_ROUTES.TOGGLE_STATUS, payload)
    }

    async createAddress(payload: ApiRequestBody<typeof VENDOR_ROUTES.CREATE_ADDRESS, "post">) {
        return this.post(VENDOR_ROUTES.CREATE_ADDRESS, payload)
    }

    async getAddress(id: string) {
        return this.get(VENDOR_ROUTES.ADDRESS_BY_ID, { params: { id } })
    }
}
