import Joi from 'joi';
import { AuthSpecification, AuthSpecificationSchema, Carrier, CarrierSchema } from '.';

export interface CarrierAppMetadata {
  /** @description The id for this integration (this GUID should not be changed after publishing) */
  Id: string;
  /** @description The name of this integration, used for internal purposes, can be the same as the branded Carrier in Carriers[] */
  Name: string;
  /** @description The specification for authorizing with this carrier */
  AuthProcess?: AuthSpecification;
  /** @description A list of branded carriers */
  Carriers: Carrier[];
}

export const CarrierAppMetadataSchema = Joi.object({
  Id: Joi.string().uuid().required(),
  Name: Joi.string().required(),
  AuthProcess: AuthSpecificationSchema.optional(),
  Carriers: Joi.array()
    .unique('Id')
    .required()
    .min(1)
    .message('There must be at least 1 Carrier defined')
    .items(CarrierSchema),
});
