const Joi = require("joi");
const {
  mobileNo,
  firstName,
  lastName,
  email,
  password,
  userName,
} = require("./CommonValidation");
const { Validate } = require("./Validate");

const RegisterValidation = async (req, res, next) => {
  const schema = Joi.object().keys({
    mobileNo: mobileNo,
    firstName: firstName,
    lastName: lastName,
    email: email,
    password: password,
    userType: Joi.string().default("user").valid("user", "agent").optional(),
    userName: userName,
  });
  await Validate(req, res, next, schema);
};

const SendOTPValidation = async (req, res, next) => {
  const schema = Joi.object().keys({
    mobileNo: mobileNo,
    countryCode: Joi.string().required(),
    type: Joi.string().default("user").valid("user", "agent").optional(),
  });
  await Validate(req, res, next, schema);
};

const VerifyOTPValidation = async (req, res, next) => {
  const schema = Joi.object().keys({
    mobileNo: mobileNo,
    otp: Joi.number().required(),
  });
  await Validate(req, res, next, schema);
};

const SocialAuthenticationValidation = async (req, res, next) => {
  console.log(req.body);
  const schema = Joi.object()
    .keys({
      name: firstName,
      email: email,
      photo: Joi.string().required().messages({
        "any:required": "Photo field is required",
      }),
    })
    .unknown(true);
  await Validate(req, res, next, schema);
};

const LoginValidation = async (req, res, next) => {
  const schema = Joi.object().keys({
    password: password,
    userName: userName,
    notificationToken: Joi.string().optional(),
    loginType: Joi.string().valid("agent", "user").optional(),
  });
  await Validate(req, res, next, schema);
};

const ForgetPasswordValidation = async (req, res, next) => {
  const schema = Joi.object().keys({
    email: email,
  });
  await Validate(req, res, next, schema);
};

module.exports = {
  RegisterValidation,
  LoginValidation,
  ForgetPasswordValidation,
  SocialAuthenticationValidation,
  SendOTPValidation,
  VerifyOTPValidation,
};
