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

export const EMPLOYEE_ROUTES = {
    INDEX: "/api/employees",
    BY_ID: "/api/employees/{id}",
    UPDATE_PERMISSIONS: "/api/employees/{id}/update-permissions",
} as const satisfies Record<string, ApiPath>

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

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

    async updatePermissions(id: string, payload: ApiRequestBody<typeof EMPLOYEE_ROUTES.UPDATE_PERMISSIONS, "post">) {
        return this.post(EMPLOYEE_ROUTES.UPDATE_PERMISSIONS, payload as never, { params: { id } } as never)
    }
}
