'use strict';

// load deps
const Joi = require('joi');

const ProductValidator = {
  list,
  read,
  create,
  update,
  destroy
};

module.exports = ProductValidator;

const schema = {
  name: Joi
    .string()
    .min(1)
    .max(100)
    .trim(),
  description: Joi
    .string()
    .default(''),
  model: Joi
    .string()
    .min(1)
    .max(50)
    .trim(),
  upc: Joi
    .string()
    .max(13)
    .trim(),
  price: Joi
    .number()
    .precision(2)
    .positive(),
  status: Joi
    .boolean()
    .default(false)
};

function list () {
  return {};
}

function read () {
  return {
    params: {
      id: Joi
        .number()
        .integer()
        .positive()
        .required()
    }
  };
}

function create () {
  return {
    payload: {
      name: schema
        .name
        .required(),
      description: schema
        .description
        .optional(),
      model: schema
        .model
        .optional(),
      upc: schema
        .upc
        .optional(),
      price: schema
        .price
        .required(),
      status: schema
        .status
        .optional()
    }
  };
}

function update () {
  return {
    params: {
      id: Joi
        .number()
        .integer()
        .positive()
        .required()
    },
    payload: {
      name: schema
        .name
        .optional(),
      description: schema
        .description
        .optional(),
      model: schema
        .model
        .optional(),
      upc: schema
        .upc
        .optional(),
      price: schema
        .price
        .optional(),
      status: schema
        .status
        .optional()
    }
  };
}

function destroy () {
  return {
    params: {
      id: Joi
        .number()
        .integer()
        .positive()
        .required()
    }
  };
}


@@ -474,16 +474,96 @@
 tive(),%0A
+  category: Joi%0A    .array()%0A    .items(Joi.number().positive())%0A    .single(),%0A
   status
@@ -564,24 +564,24 @@
 status: Joi%0A
-
     .boolean
@@ -1120,24 +1120,86 @@
 required(),%0A
+      category: schema%0A        .category%0A        .optional(),%0A
       status
@@ -1658,32 +1658,32 @@
   price: schema%0A
-
         .price%0A 
@@ -1694,32 +1694,94 @@
    .optional(),%0A
+      category: schema%0A        .category%0A        .optional(),%0A
       status: sc

Fix product validation