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

export interface IUpdateUser_Request_DTO {
  name: string;
  email: string;
  password: string;
}

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

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

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

  return Result.ok(true);
}
