import {
  adminProcedure,
  createTRPCRouter,
  protectedProcedure,
  resourceOverviewProcedure,
} from "../trpc.js";
import {
  countryIdInputSchema,
  countryIdentifierInputSchema,
  countryListInputSchema,
  countryUpdateInputSchema,
  createCountry,
  createMetroCity,
  deleteMetroCity,
  getCountryById,
  getCountryByIdentifier,
  getMetroCityById,
  listCountries,
  metroCityIdInputSchema,
  metroCityUpdateInputSchema,
  resolveCountryByIdentifier,
  updateCountry,
  updateMetroCity,
} from "./country-procedure-support.js";
import { CreateCountrySchema, CreateMetroCitySchema } from "@capakraken/shared";

export const countryRouter = createTRPCRouter({
  list: protectedProcedure
    .input(countryListInputSchema)
    .query(({ ctx, input }) => listCountries(ctx, input)),

  resolveByIdentifier: protectedProcedure
    .input(countryIdentifierInputSchema)
    .query(({ ctx, input }) => resolveCountryByIdentifier(ctx, input)),

  getByIdentifier: resourceOverviewProcedure
    .input(countryIdentifierInputSchema)
    .query(({ ctx, input }) => getCountryByIdentifier(ctx, input)),

  getById: resourceOverviewProcedure
    .input(countryIdInputSchema)
    .query(({ ctx, input }) => getCountryById(ctx, input)),

  getCityById: protectedProcedure
    .input(metroCityIdInputSchema)
    .query(({ ctx, input }) => getMetroCityById(ctx, input)),

  create: adminProcedure
    .input(CreateCountrySchema)
    .mutation(({ ctx, input }) => createCountry(ctx, input)),

  update: adminProcedure
    .input(countryUpdateInputSchema)
    .mutation(({ ctx, input }) => updateCountry(ctx, input)),

  // ─── Metro City ─────────────────────────────────────────────

  createCity: adminProcedure
    .input(CreateMetroCitySchema)
    .mutation(({ ctx, input }) => createMetroCity(ctx, input)),

  updateCity: adminProcedure
    .input(metroCityUpdateInputSchema)
    .mutation(({ ctx, input }) => updateMetroCity(ctx, input)),

  deleteCity: adminProcedure
    .input(metroCityIdInputSchema)
    .mutation(({ ctx, input }) => deleteMetroCity(ctx, input)),
});
