export type CreateApiTripTemplatesArgs = {body: {departure_days: Array<'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'>, start_departure_date: string, end_departure_date: string, coach_id: number, cts_route_id?: number | undefined, departure_time: string, counter_ids?: string | undefined, future_relations?: (Array<'counters' | 'sgd_agents' | 'myr_agents'>) | undefined, has_alias_departure?: boolean | undefined, 'segments[departure_station_id]': Array, 'segments[arrival_station_id]': Array, 'segments[available_after_station_id]'?: Array | undefined, 'segments[blocked_seat_numbers]'?: Array | undefined, 'segments[prices][currency]': Array<'MYR' | 'SGD'>, 'segments[prices][normal_price]'?: Array | undefined, 'segments[prices][return_price]'?: Array | undefined, 'segments[prices][online_price]'?: Array | undefined, 'segments[prices][agent_price]'?: Array | undefined, 'segments[prices][spad_price]'?: Array | undefined, 'agents[agent_id]': Array, 'agents[commission_type]': Array<'none' | 'default' | 'custom'>, 'agents[custom_commission_type]'?: (Array<'percent' | 'MYR' | 'SGD'>) | undefined, 'agents[custom_commission_value]'?: Array | undefined, 'cts_routes[cts_user_id]': Array, 'cts_routes[cts_route_id]': Array, 'cts_routes[enabled]': Array, name: string}}; export type CreateApiTripTemplatesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create trip template * * POST /trip_templates */ export const createApiTripTemplates = async (args: CreateApiTripTemplatesArgs, options?: CreateApiTripTemplatesOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") const url = `${baseUrl.replace(/\/+$/, '')}/trip_templates${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };