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

export interface ICreateUser_Request_DTO {
  id: string;
  name: string;
  email: string;
  password: string;
}

export function ensureCreateUser_Request_DTOIsValid(
  userDTO: ICreateUser_Request_DTO,
) {
  const schema = Joi.object({
    id: Joi.string(),
    name: Joi.string(),
    email: Joi.string(),
    password: Joi.string(),
  }).unknown(true);

  const result = RuleValidator.validate<ICreateUser_Request_DTO>(
    schema,
    userDTO,
  );

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

  return Result.ok(true);
}
