import Joi from 'joi';
import {
  PackageRatingGroupDimensions,
  PackageRatingGroupDimensionsSchema,
} from './package-rating-group-dimensions';
import {
  PackageRatingGroupWeight,
  PackageRatingGroupWeightSchema,
} from './package-rating-group-weight';

/** @description Details about how packages are related to rates */
export interface PackageRatingGroup {
  /** @description Id of the rating group */
  Id: string;
  /** @description Id of the package type to which this rating group corresponds */
  PackageTypeId: string;
  /** @description Name of the package rating group */
  Name: string;
  /** @description This is the code that will be sent to requests, this should be the same code the carrier's api would expect */
  CarrierPackageTypeCode: string;
  /** @description Maximum allowable dimensions of packages for the rating group */
  DimensionLimits?: PackageRatingGroupDimensions;
  /** @description Maximum allowable weight of packages for the rating group */
  MaxWeight?: PackageRatingGroupWeight;
}

export const PackageRatingGroupSchema = Joi.object({
  Id: Joi.string().required().max(50),
  PackageTypeId: Joi.string().uuid().required(),
  Name: Joi.string().required().max(50),
  CarrierPackageTypeCode: Joi.string().required().max(50), // Copied from package type validation
  DimensionLimits: PackageRatingGroupDimensionsSchema.optional(),
  MaxWeight: PackageRatingGroupWeightSchema.optional(),
});
