import * as gracely from "gracely" import * as isoly from "isoly" import * as authly from "authly" import { Merchant } from "./index" import { Reconciliation as MerchantReconciliation } from "./Reconciliation" import { Rules as MerchantRules } from "./Rules" export interface Base { activated?: isoly.Date categoryCode: string //mcc country: isoly.CountryCode.Alpha2 currency: isoly.Currency descriptor?: string | { statement: string; soft: boolean } id: authly.Identifier name: string number?: string psp?: typeof Base.psps[number] reconciliation: MerchantReconciliation rules: MerchantRules storage?: "cosmos" | "cloudly" type: "test" | "live" } export namespace Base { export const psps = ["intergiro", "cleanpay", "devcode", "transact365"] export function is(value: any | Base): value is Base { return ( typeof value == "object" && value && (value.activated == undefined || isoly.Date.is(value.activated)) && typeof value.categoryCode == "string" && isoly.CountryCode.Alpha2.is(value.country) && (value.created == undefined || isoly.Date.is(value.created)) && isoly.Currency.is(value.currency) && (value.descriptor == undefined || typeof value.descriptor == "string" || (typeof value.descriptor == "object" && value.descriptor && value.descriptor.statement == "string" && typeof value.descriptor.soft == "boolean")) && authly.Identifier.is(value.id, 8) && typeof value.name == "string" && (value.number == undefined || typeof value.number == "string") && (value.psp == undefined || psps.includes(value.psp)) && MerchantReconciliation.is(value.reconciliation) && MerchantRules.is(value.rules) && (value.storage == undefined || value.storage == "cosmos" || value.storage == "cloudly") && (value.type == "test" || value.type == "live") ) } export function from(value: Merchant): Base { return { activated: value.activated, categoryCode: value.categoryCode, country: value.country, currency: value.currency, descriptor: value.descriptor, id: value.id, name: value.name, number: value.number, psp: value.psp, reconciliation: value.reconciliation, rules: value.rules, type: value.type, storage: value.storage, } } export function flaw(value: any | Base): gracely.Flaw { return { type: "Merchant", flaws: typeof value != "object" || !value ? undefined : ([ value.activated == undefined || typeof value.activated == "string" || { property: "activated", type: "string" }, typeof value.categoryCode == "string" || { property: "categoryCode", type: "string" }, isoly.CountryCode.Alpha2.is(value.country) || { property: "country", type: "isoly.CountryCode.Alpha2" }, isoly.Currency.is(value.currency) || { property: "currency", type: "isoly.Currency" }, value.descriptor == undefined || typeof value.descriptor == "string" || (typeof value.descriptor == "object" && value.descriptor && value.descriptor.statement == "string" && typeof value.descriptor.soft == "boolean") || { property: "descriptor", type: "string | { statement: string, soft: boolean } | undefined", }, authly.Identifier.is(value.id, 8) || { property: "id", type: "authly.Identifier" }, typeof value.name == "string" || { property: "name", type: "string" }, value.number == undefined || typeof value.number == "string" || { property: "number", type: "string | undefined" }, value.psp == undefined || psps.includes(value.psp) || { property: "psp", type: "${psps} | undefined" }, MerchantReconciliation.is(value.reconciliation) || MerchantReconciliation.flaw(value.reconciliation), MerchantRules.is(value.rules) || MerchantRules.flaw(value.rules), value.storage == undefined || value.storage == "cosmos" || value.storage == "cloudly" || { property: "storage", type: '"cosmos" | "cloudly" | undefined', }, value.type == "test" || value.type == "live" || { property: "type", type: '"test" | "live"' }, ].filter(gracely.Flaw.is) as gracely.Flaw[]), } } }