import api from 'src/config/api';
import {
  type GetPathsParams,
  type GetPathsResponse,
  type Path,
  PathOrderBy,
  PathStatus,
} from 'src/pages/dashboard/learning/paths/types';

export const getPaths = ({
  status,
  search,
  order = 'ASC',
  orderBy: pathOrderBy = PathOrderBy.DEFAULT,
  ...pagination
}: GetPathsParams) => {
  let orderBy = [pathOrderBy, order].join('_');
  if (pathOrderBy === PathOrderBy.DEFAULT) orderBy = pathOrderBy;

  return api.get<GetPathsResponse>('learning-paths', {
    params: {
      q: search || undefined,
      status: status === PathStatus.ALL ? undefined : status,
      orderBy,
      ...pagination,
    },
  });
};

export const getPath = (pathId: number) =>
  api.get<Path>(`learning-paths/${pathId}`);

export const getCertificate = (pathId: number) =>
  api.post<Path>(`learning-paths/${pathId}/cert`);
