import { createSearchParamsCache, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, } from "nuqs/server" import * as z from "zod" import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" import { ItemOffshoreTop, ItemOffshoreHull, ItemShipbuilding } from "@/db/schema/items"; // 조선 아이템 검색 파라미터 캐시 export const shipbuildingSearchParamsCache = createSearchParamsCache({ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), page: parseAsInteger.withDefault(1), perPage: parseAsInteger.withDefault(10), sort: getSortingStateParser().withDefault([ { id: "createdAt", desc: true }, ]), itemCode: parseAsString.withDefault(""), workType: parseAsString.withDefault(""), shipTypes: parseAsString.withDefault(""), itemList: parseAsString.withDefault(""), filters: getFiltersStateParser().withDefault([]), joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), shipFilters: getFiltersStateParser().withDefault([]), shipJoinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), search: parseAsString.withDefault(""), }) // 해양 TOP 아이템 검색 파라미터 캐시 export const offshoreTopSearchParamsCache = createSearchParamsCache({ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), page: parseAsInteger.withDefault(1), perPage: parseAsInteger.withDefault(10), sort: getSortingStateParser().withDefault([ { id: "createdAt", desc: true }, ]), itemCode: parseAsString.withDefault(""), workType: parseAsString.withDefault(""), itemList: parseAsString.withDefault(""), subItemList: parseAsString.withDefault(""), filters: getFiltersStateParser().withDefault([]), joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), topFilters: getFiltersStateParser().withDefault([]), topJoinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), search: parseAsString.withDefault(""), }) // 해양 HULL 아이템 검색 파라미터 캐시 export const offshoreHullSearchParamsCache = createSearchParamsCache({ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), page: parseAsInteger.withDefault(1), perPage: parseAsInteger.withDefault(10), sort: getSortingStateParser().withDefault([ { id: "createdAt", desc: true }, ]), itemCode: parseAsString.withDefault(""), workType: parseAsString.withDefault(""), itemList: parseAsString.withDefault(""), subItemList: parseAsString.withDefault(""), filters: getFiltersStateParser().withDefault([]), joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), hullFilters: getFiltersStateParser().withDefault([]), hullJoinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), search: parseAsString.withDefault(""), }) // 조선 아이템 업데이트 스키마 export const updateShipbuildingItemSchema = z.object({ itemCode: z.string(), workType: z.enum(["기장", "전장", "선실", "배관", "철의", "선체"]).optional(), shipTypes: z.string().optional(), itemList: z.string().optional(), }) export type GetShipbuildingSchema = Awaited> export type GetOffshoreTopSchema = Awaited> export type GetOffshoreHullSchema = Awaited> export type UpdateShipbuildingItemSchema = z.infer // 조선 아이템 스키마 export const createShipbuildingItemSchema = z.object({ itemCode: z.string(), workType: z.enum(["기장", "전장", "선실", "배관", "철의", "선체"]), shipTypes: z.string(), itemList: z.string().optional(), }) export type CreateShipbuildingItemSchema = z.infer // 조선 아이템 생성 데이터 타입 export interface ShipbuildingItemCreateData { itemCode: string workType: "기장" | "전장" | "선실" | "배관" | "철의" | "선체" | null shipTypes: string | null itemList?: string | null } // 아이템 타입에 따른 생성 데이터 타입 export type TypedItemCreateData = ShipbuildingItemCreateData // 해양 TOP 아이템 스키마 export const createOffshoreTopItemSchema = z.object({ itemCode: z.string(), workType: z.enum(["TM", "TS", "TE", "TP"]), itemList: z.string().optional(), subItemList: z.string().optional(), }) // 해양 HULL 아이템 스키마 export const createOffshoreHullItemSchema = z.object({ itemCode: z.string(), workType: z.enum(["HA", "HE", "HH", "HM", "HO", "HP", "NC"]), itemList: z.string().optional(), subItemList: z.string().optional(), }) export type CreateOffshoreTopItemSchema = z.infer export type CreateOffshoreHullItemSchema = z.infer // 해양 TOP 아이템 업데이트 스키마 export const updateOffshoreTopItemSchema = z.object({ itemCode: z.string(), workType: z.enum(["TM", "TS", "TE", "TP"]).optional(), itemList: z.string().optional(), subItemList: z.string().optional(), }) // 해양 HULL 아이템 업데이트 스키마 export const updateOffshoreHullItemSchema = z.object({ itemCode: z.string(), workType: z.enum(["HA", "HE", "HH", "HM", "HO", "HP", "NC"]).optional(), itemList: z.string().optional(), subItemList: z.string().optional(), }) export type UpdateOffshoreTopItemSchema = z.infer export type UpdateOffshoreHullItemSchema = z.infer // 해양 TOP 아이템 생성 데이터 타입 export interface OffshoreTopItemCreateData { itemCode: string workType: "TM" | "TS" | "TE" | "TP" itemList?: string | null subItemList?: string | null } // 해양 HULL 아이템 생성 데이터 타입 export interface OffshoreHullItemCreateData { itemCode: string workType: "HA" | "HE" | "HH" | "HM" | "HO" | "HP" | "NC" itemList?: string | null subItemList?: string | null }