import * as isoly from "isoly" import * as selectively from "selectively" import * as base from "@payfunc/model-base" import * as utilities from "../utilities" export interface Contact { type?: "organization" | "person" id?: string number?: string name?: string address?: base.Address.General email?: string phone?: string } export namespace Contact { export function is(value: any | Contact): value is Contact { return ( typeof value == "object" && value && (value.type == undefined || ["organization", "person"].includes(value.type)) && (value.id == undefined || typeof value.id == "string") && (value.number == undefined || typeof value.number == "string") && (value.name == undefined || typeof value.name == "string") && (value.address == undefined || base.Address.General.is(value.address)) && (value.email == undefined || typeof value.email == "string") && (value.phone == undefined || typeof value.phone == "string") ) } export function from(value: base.Contact): Contact { return utilities.clear({ type: value.type, id: value.id, number: value.number, name: value.name ? base.Name.get(value.name) : undefined, address: value.address ? base.Addresses.get(value.address) : undefined, email: value.email ? base.EmailAddresses.get(value.email) : undefined, phone: value.phone ? base.PhoneNumbers.get(value.phone) : undefined, }) } export const template = new selectively.Type.Object({ type: new selectively.Type.Union([ new selectively.Type.String("organization"), new selectively.Type.String("person"), ]), id: new selectively.Type.String(), number: new selectively.Type.String(), name: new selectively.Type.String(), address: new selectively.Type.Object({ address1: new selectively.Type.String(), address2: new selectively.Type.String(), address3: new selectively.Type.String(), street: new selectively.Type.String(), zipCode: new selectively.Type.String(), city: new selectively.Type.String(), state: new selectively.Type.String(), countryCode: new selectively.Type.Union([ ...isoly.CountryCode.Alpha2.types.map(c => new selectively.Type.String(c)), new selectively.Type.String(""), ]), }), email: new selectively.Type.String(), phone: new selectively.Type.String(), }) }