import type { LocationQuery, LocationQueryRaw } from 'vue-router';

import {
  buildListRouteStateQuery,
  defineListRouteStateSchema,
  mergeListRouteStateQuery,
  parseListRouteState,
  positiveIntegerListRouteField,
  stringListRouteField,
} from '#/composables/useListRouteState';

interface WorkflowListRouteState {
  categoryId: string;
  keyword: string;
  pageNumber: number;
  pageSize: number;
}

const workflowListRouteSchema =
  defineListRouteStateSchema<WorkflowListRouteState>({
    path: '/ai/workflow',
    fields: {
      categoryId: stringListRouteField(),
      keyword: stringListRouteField(),
      pageNumber: positiveIntegerListRouteField({ defaultValue: 1 }),
      pageSize: positiveIntegerListRouteField({
        allowedValues: [12, 18, 24],
        defaultValue: 12,
      }),
    },
  });

function parseWorkflowListRouteState(
  query: LocationQuery,
): WorkflowListRouteState {
  return parseListRouteState(query, workflowListRouteSchema);
}

function buildWorkflowListRouteQuery(
  state: WorkflowListRouteState,
): LocationQueryRaw {
  return buildListRouteStateQuery(state, workflowListRouteSchema);
}

function mergeWorkflowListRouteQuery(
  query: LocationQuery,
  state: WorkflowListRouteState,
): LocationQueryRaw {
  return mergeListRouteStateQuery(query, state, workflowListRouteSchema);
}

export {
  buildWorkflowListRouteQuery,
  mergeWorkflowListRouteQuery,
  parseWorkflowListRouteState,
  workflowListRouteSchema,
};
export type { WorkflowListRouteState };
