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

export interface IUpdateDealer_Request_DTO {
  name: string;
  lang_code: string;
  contact_information: string;
  default_payment_method: string;
  default_notes: string;
  default_legal_terms: string;
  default_quote_validity: string;
}

export function ensureUpdateDealer_Request_DTOIsValid(dealerDTO: IUpdateDealer_Request_DTO) {
  const schema = Joi.object({
    name: Joi.string(),
    lang_code: Joi.string(),
    contact_information: Joi.string(),
    default_payment_method: Joi.string(),
    default_notes: Joi.string(),
    default_legal_terms: Joi.string(),
    default_quote_validity: Joi.string(),
  }).unknown(true);

  const result = RuleValidator.validate<IUpdateDealer_Request_DTO>(schema, dealerDTO);

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

  return Result.ok(true);
}
