const AppError = require('../utils/appError')
const { sanitizePayload } = require('../utils/sanitize')

function validateLoginBody(body = {}) {
    const payload = sanitizePayload(body)

    if (!payload.users_wx_code) {
        throw new AppError('users_wx_code 为必填项', 400)
    }

    return payload
}

function validateProfileEditBody(body = {}) {
    const payload = sanitizePayload(body)

    if (!payload.users_name) {
        throw new AppError('users_name 为必填项', 400)
    }

    if (!payload.users_phone_code) {
        throw new AppError('users_phone_code 为必填项', 400)
    }

    if (!payload.users_picture) {
        throw new AppError('users_picture 为必填项', 400)
    }

    return payload
}

module.exports = {
    validateLoginBody,
    validateProfileEditBody,
}
