import {z} from 'zod' export type DtosPlanBenefits = {deductible?: string | undefined, office_visit?: string | undefined, inpatient?: string | undefined, outpatient?: string | undefined, emergency_room?: string | undefined, rx?: string | undefined, lab_x_ray?: string | undefined, out_of_network?: string | undefined, out_of_pocket_max?: string | undefined, preventive?: string | undefined, basic?: string | undefined, major?: string | undefined, ortho?: string | undefined, annual_benefit_max?: string | undefined, exam?: string | undefined, materials?: string | undefined, eye_glass_lenses?: string | undefined, frame_allowance?: string | undefined, contact_lenses?: string | undefined, exam_service_interval?: string | undefined, lenses_and_frame_service_interval?: string | undefined, coinsurance?: string | undefined, other?: string | undefined, ee_benefit_type?: ('NONE' | 'Flat Amount' | 'X Earnings' | '% Employee' | 'Increments' | 'Custom' | 'Custom (Based Off Employee Selection)') | undefined, is_volume_plan?: boolean | undefined, volume_basis_percent?: string | undefined, ee_earnings_min?: string | undefined, ee_earnings_max?: string | undefined, ee_increment_from?: string | undefined, ee_increment_to?: string | undefined, ee_increment_by?: string | undefined, ee_flat_amount?: string | undefined, ee_guaranteed_issue?: string | undefined, sp_percentage?: string | undefined, ch_percentage?: string | undefined, request_primary_care_provider_id?: boolean | undefined, request_primary_care_provider_name?: boolean | undefined}; export type DtosPlanDocumentEditable = {name: string, url?: string | undefined, requires_review?: boolean | undefined, type?: string | undefined, system_type?: string | undefined}; export type DtosEligibilityContributions = {contribution_detail: 'Table' | 'Tier' | 'Custom' | 'Tier-Tobacco', contribution_type: 'Employee' | 'Employer' | 'Base Plan', base_plan_id?: string | undefined, dependents?: string | undefined, ee?: string | undefined, es?: string | undefined, e_s1c?: string | undefined, e_s2c?: string | undefined, e_s3c?: string | undefined, e1c?: string | undefined, e2c?: string | undefined, e3c?: string | undefined, ee_tobacco?: string | undefined, es_tobacco?: string | undefined, e_s1c_tobacco?: string | undefined, e_s2c_tobacco?: string | undefined, e_s3c_tobacco?: string | undefined, e1c_tobacco?: string | undefined, e2c_tobacco?: string | undefined, e3c_tobacco?: string | undefined, employee?: string | undefined, spouse?: string | undefined, children?: string | undefined, employee_tobacco?: string | undefined, spouse_tobacco?: string | undefined, child1?: string | undefined, child2?: string | undefined, child3?: string | undefined, family?: string | undefined, overall_max?: string | undefined, apply_base_plan_amount_to_employee_only?: boolean | undefined}; export type DtosPlanEligibility = {name: string, policy_number?: string | undefined, entry_date?: ('' | 'First of the Month' | 'First of the Month Next Following' | '15th of the Month' | 'Immediate' | 'Semi-Annual' | 'Quarterly' | 'First of the Month (Coinciding)') | undefined, job_classes?: Array | undefined, departments?: Array | undefined, divisions?: Array | undefined, locations?: Array | undefined, ineligible_employees?: Array | undefined, scheduled_hours_min?: number | undefined, scheduled_hours_max?: number | undefined, age_determination?: ('Plan Anniversary' | 'Plan Anniversary (Ignore Hire Date)' | 'Current Year - Birth Year' | 'End of the Month' | 'First of the Month' | 'First of the Year' | 'Original Effective Date') | undefined, waiting_period?: number | undefined, waiting_period_type?: ('Days' | 'Months' | '') | undefined, contributions?: DtosEligibilityContributions | undefined}; export type DtosPlanImportCarrierFields = {plan_code?: string | undefined, plan_type_code?: string | undefined, supplemental_identifier?: string | undefined}; export type DtosEligibilityRates = {rate_type: 'Table' | 'Tier-Table' | 'Tier', plan_type?: string | undefined, rate_basis?: string | undefined, rate_adjustment_factor?: string | undefined, per_unit?: number | undefined, tier_employee?: string | undefined, tier_spouse?: string | undefined, tier_children?: string | undefined, tier_dependents?: string | undefined, tier_ee?: string | undefined, tier_es?: string | undefined, tier_e_s1c?: string | undefined, tier_e_s2c?: string | undefined, tier_e_s3c?: string | undefined, tier_e1c?: string | undefined, tier_e2c?: string | undefined, tier_e3c?: string | undefined, tier_rates_tobacco?: Array | undefined, tier_table_rates_ee_only?: Array | undefined, tier_table_rates_eesp?: Array | undefined, tier_table_rates_e_e1ch?: Array | undefined, tier_table_rates_eech?: Array | undefined, tier_table_rates_family?: Array | undefined, tier_table_rates_ee_only_tobacco?: Array | undefined, tier_table_rates_eesp_tobacco?: Array | undefined, tier_table_rates_e_e1ch_tobacco?: Array | undefined, tier_table_rates_eech_tobacco?: Array | undefined, tier_table_rates_family_tobacco?: Array | undefined, tier_table_rates_ee_only_male?: Array | undefined, tier_table_rates_eesp_male?: Array | undefined, tier_table_rates_e_e1ch_male?: Array | undefined, tier_table_rates_eech_male?: Array | undefined, tier_table_rates_family_male?: Array | undefined, tier_table_rates_ee_only_female?: Array | undefined, tier_table_rates_eesp_female?: Array | undefined, tier_table_rates_e_e1ch_female?: Array | undefined, tier_table_rates_eech_female?: Array | undefined, tier_table_rates_family_female?: Array | undefined, table_columns?: ('Rates' | 'Employee & Spouse Rates' | 'Gender Rates' | 'Tobacco Rates' | 'Gender & Tobacco Rates' | 'Employee & Spouse & Tobacco Rates' | 'Employee & Spouse & Child Rates') | undefined, tier_table_columns?: ('Rates' | 'Gender Rates' | 'Tobacco Rates') | undefined, table_rates?: Array | undefined, table_employee?: Array | undefined, table_spouse?: Array | undefined, table_employee_tobacco?: Array | undefined, table_spouse_tobacco?: Array | undefined, table_child?: Array | undefined, table_male?: Array | undefined, table_female?: Array | undefined, table_tobacco?: Array | undefined, table_male_tobacco?: Array | undefined, table_female_tobacco?: Array | undefined, table_child1?: string | undefined, table_child2?: string | undefined, table_child3?: string | undefined, age_band_type?: ('All Ages (starting with 0-17)' | 'All Ages' | '5 Year Age Bands' | '10 Year Age Bands') | undefined, base_spouse_age_off_employee?: boolean | undefined, base_spouse_tobacco_off_employee?: boolean | undefined, base_adult_children_off_age?: boolean | undefined, rate_library_plan_id?: string | undefined, rate_library_name?: string | undefined}; export type DtosPlanImport = {plan_id: string, previous_plan_id?: string | undefined, carrier?: string | undefined, name: string, admin_name?: string | undefined, type: string, start_date: string, end_date?: string | undefined, instructions?: string | undefined, deduction_periods?: number | undefined, benefits?: DtosPlanBenefits | undefined, cobra_eligibility?: ('Not Eligible' | 'Eligible - 100%' | 'Eligible - 102%' | 'Eligible - 110%' | 'Eligible - 105%') | undefined, documents?: Array | undefined, eligibilities?: Array | undefined, carrier_fields?: DtosPlanImportCarrierFields | undefined, rates?: DtosEligibilityRates | undefined, form_ids?: Array | undefined}; export type CreateApiVVersionCompaniesCompanyIdPlansArgs = {company_id: string, version: string, body: DtosPlanImport}; export type CreateApiVVersionCompaniesCompanyIdPlansOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dtosPlansResultPlanInfo = z.object({external_id: z.string().optional(), id: z.string().optional(), import_id: z.string().optional()}); export const controllersEmployeeResult = z.object({external_id: z.string().optional(), id: z.string().optional()}); export const dtosPlanImportPlansResult = z.object({company_id: z.string().optional(), plans: z.array(dtosPlansResultPlanInfo).optional(), employees: z.array(controllersEmployeeResult).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * company plan * * POST /v{version}/companies/{company_id}/plans */ export const createApiVVersionCompaniesCompanyIdPlans = async (args: CreateApiVVersionCompaniesCompanyIdPlansArgs, options: CreateApiVVersionCompaniesCompanyIdPlansOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v${encodeURIComponent(String(args.version))}/companies/${encodeURIComponent(String(args.company_id))}/plans${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dtosPlanImportPlansResult, await res.json()) };