// ========================
// Device Validation

const Joi = require("joi");

// ========================
const timePattern = /^([01]\d|2[0-3]):([0-5]\d)(:[0-5]\d)?$/;

const insertShiftSchema = Joi.object({
  shift_name: Joi.string().max(100).required(),
  is_active:Joi.boolean().required(),
  start_time: Joi.string()
    .pattern(timePattern)
    .required()
    .messages({
      "string.pattern.base": "start_time harus dalam format HH:mm atau HH:mm:ss",
    }),
  end_time: Joi.string()
    .pattern(timePattern)
    .required()
    .messages({
      "string.pattern.base": "end_time harus dalam format HH:mm atau HH:mm:ss",
    }),
});

const updateShiftSchema = Joi.object({
  shift_name: Joi.string().max(100).optional(),
  is_active:Joi.boolean().optional(),
  start_time: Joi.string()
    .pattern(timePattern)
    .messages({
      "string.pattern.base": "start_time harus dalam format HH:mm atau HH:mm:ss",
    }).optional(),
  end_time: Joi.string()
    .pattern(timePattern)
    .messages({
      "string.pattern.base": "end_time harus dalam format HH:mm atau HH:mm:ss",
    }),
}).min(1);

module.exports = {
  insertShiftSchema,
  updateShiftSchema,
};
