
const { body, validationResult } = require('express-validator')

const Complaint = require('../models/Complaint')
const { _sr } = require('../plugins/serverResponses')
const {  checkValidations } = require('../plugins/controllersHelperFunctions')
const _faSr = _sr.fa


module.exports.create = [
  [
    body('fullName').notEmpty().withMessage(_faSr.required.name),
    body('national').notEmpty().withMessage(_faSr.required.national_code),
    body('phoneNumber').notEmpty().isMobilePhone().withMessage(_faSr.required.phone_number),
    body('email').notEmpty().isEmail().withMessage(_faSr.required.email),
    body('deviceNumber').notEmpty().withMessage(_faSr.required.field),
    body('receptionCode').notEmpty().withMessage(_faSr.required.field),
    body('caption').notEmpty().withMessage(_faSr.required.caption),
    body('callType').notEmpty().isBoolean().withMessage(_faSr.required.field),

  ],
  checkValidations(validationResult),
  async(req, res) => {

    const complaint = await Complaint.create(req.body)

    res.status(201).json(complaint)

  }
]


module.exports.gets = [
  async(req, res)=>{
    const complaints = await Complaint.find()

    res.status(200).json(complaints)

  }
]

module.exports.get = [
  async(req, res)=>{
    const complaint = await Complaint.findById(req.params.id)

    res.status(200).json(complaint)

  }
]
