const HttpException = require('../../../utils/HttpException.js');

exports.validateStoreHospitalRequest = (body) => {
    const { name, hospital_code, type, ownership, province_id, city_id, address, contact, note } = body;

    const errors = {};

    if (!name || name.trim() === '') {
        errors.name = ['name is required'];
    }

    if (!hospital_code || hospital_code.trim() === '') {
        errors.hospital_code = ['hospital code is required'];
    }

    if (!type || type.trim() === '') {
        errors.type = ['type is required'];
    }

    if (!ownership || ownership.trim() === '') {
        errors.ownership = ['ownership is required'];
    }

    if (!province_id || province_id.trim() === '') {
        errors.province_id = ['province id is required'];
    }

    if (!city_id || city_id.trim() === '') {
        errors.city_id = ['city id is required'];
    }

    if (!address || address.trim() === '') {
        errors.address = ['address is required'];
    }

    // if (!simrs_type || simrs_type.trim() === '') {
    //     errors.simrs_type = ['simrs type is required'];
    // }

    if (!contact || contact.trim() === '') {
        errors.contact = ['contact is required'];
    }

    if (!note || note.trim() === '') {
        errors.note = ['note is required'];
    }

    if (Object.keys(errors).length > 0) {
        throw new HttpException(errors, 422);
    }

    return {
        name: name.trim(),
        hospital_code: hospital_code.trim(),
        type: type.trim(),
        ownership: ownership.trim(),
        province_id: province_id.trim(),
        city_id: city_id.trim(),
        address: address.trim(),
        // simrs_type: simrs_type.trim(),
        contact: contact.trim(),
        note: note.trim(),
    };
};

exports.validateUpdateHospitalRequest = (body) => {
    const { name, hospital_code, type, ownership, province_id, city_id, address, progress_status, contact, note } = body;

    const errors = {};

    if (!name || name.trim() === '') {
        errors.name = ['name is required'];
    }

    if (!hospital_code || hospital_code.trim() === '') {
        errors.hospital_code = ['hospital code is required'];
    }

    if (!type || type.trim() === '') {
        errors.type = ['type is required'];
    }

    if (!ownership || ownership.trim() === '') {
        errors.ownership = ['ownership is required'];
    }

    if (!province_id || province_id.trim() === '') {
        errors.province_id = ['province id is required'];
    }

    if (!city_id || city_id.trim() === '') {
        errors.city_id = ['city id is required'];
    }

    if (!address || address.trim() === '') {
        errors.address = ['address is required'];
    }

    // if (!simrs_type || simrs_type.trim() === '') {
    //     errors.simrs_type = ['simrs type is required'];
    // }

    if (!progress_status || progress_status.trim() === '') {
        errors.progress_status = ['progress status is required'];
    }

    if (!contact || contact.trim() === '') {
        errors.contact = ['contact is required'];
    }

    if (!note || note.trim() === '') {
        errors.note = ['note is required'];
    }

    if (Object.keys(errors).length > 0) {
        throw new HttpException(errors, 422);
    }

    return {
        name: name.trim(),
        hospital_code: hospital_code.trim(),
        type: type.trim(),
        ownership: ownership.trim(),
        province_id: province_id.trim(),
        city_id: city_id.trim(),
        address: address.trim(),
        // simrs_type: simrs_type.trim(),
        progress_status: progress_status.trim(),
        contact: contact.trim(),
        note: note.trim(),
    };
};