import Joi from "joi";
import { Result, RuleValidator } from "../../domain";

export interface IQuantity_DTO {
  amount: number | null;
  scale: number;
}

export function ensureQuantity_DTOIsValid(quantity: IQuantity_Request_DTO) {
  const schema = Joi.object({
    amount: Joi.number(),
    scale: Joi.number(),
  });

  const result = RuleValidator.validate<IQuantity_Request_DTO>(schema, quantity);

  if (result.isFailure) {
    return Result.fail(result.error);
  }

  return Result.ok(true);
}

export interface IQuantity_Request_DTO extends IQuantity_DTO {}
export interface IQuantity_Response_DTO extends IQuantity_DTO {}
