import { defineConfig, OptionsExport } from "orval"

const config = (name: string, url?: string) => {
  const options: OptionsExport = {
    output: {
      namingConvention: "camelCase",
      target: `src/infrastructure/repositories/${name}.ts`,
      schemas: `src/domain/types/${name}`,
      mode: "tags-split",
      // mock: {
      //   type: 'msw',
      //   indexMockFiles: true
      // },
      prettier: true,
      client: "react-query",
      allParamsOptional: false,
      propertySortOrder: "Alphabetical",
      override: {
        header: (info) => [
          "Generated by orval. Do not edit manually.",
          ...(info.title ? [info.title] : []),
          ...(info.description ? [info.description] : []),
        ],
        query: {
          useQuery: true,
          usePrefetch: true,
        },
        mutator: {
          path: "./src/infrastructure/orval/orval-axios-instance.ts",
          name: "orvalAxiosInstance",
        },
      },
    },
    input: {
      target: url ?? `./openapi/${name}.yaml`,
      filters: {
        mode: "include",
        tags: [/Ranking/, /Events/, /EventTokens/, /Stages/, /StageOrders/],
      },
    },
  }

  return options
}

export default defineConfig({
  v1api: config("v1api", "https://www.oreplay.es/api/v1/openapi/json"),
})
