const executivesHistoryService = require('../../services/admin/ExecutivesHistoryService.js');
const { ListResponse } = require('../../utils/ListResponse.js');
const { PaginationParam } = require('../../utils/PaginationParams.js');
const { errorResponse, successResponse, messageSuccessResponse } = require('../../utils/Response.js');
const { validateStoreExecutivesHistoryRequest } = require('../../validators/sales/executives_history/ExecutivesHistoriValidators.js');

exports.getAllExecutivesHistory = async (req, res) => {
    try {
        const { page, limit, search, sortBy, orderBy } = PaginationParam(req);

        const { vendor_histories, total } = await executivesHistoryService.getAllExecutivesHistoryService({
            page, limit, search, sortBy, orderBy
        }, req);

        return ListResponse({ req, res, data: vendor_histories, page, limit, total, message: 'Executives history successfully retrieved' });
    } catch (err) {
        return errorResponse(res, err);
    }
};

exports.showExecutivesHistory = async (req, res) => {
    try {
        const data = await executivesHistoryService.showExecutivesHistoryService(req);
        return successResponse(res, data, 'Success show executives history');
    } catch (err) {
        return errorResponse(res, err);
    }
};

exports.storeExecutivesHistory = async (req, res) => {
    try {
        const validatedData = validateStoreExecutivesHistoryRequest(req.body);
        await executivesHistoryService.storeExecutivesHistoryService(validatedData, req);
        return messageSuccessResponse(res, 'Success added executives history', 201);
    } catch (err) {
        return errorResponse(res, err);
    }
}

exports.updateExecutivesHistory = async (req, res) => {
    try {
        const validatedData = validateStoreExecutivesHistoryRequest(req.body);
        await executivesHistoryService.updateExecutivesHistoryService(validatedData, req);
        return messageSuccessResponse(res, 'Success update executives history');
    } catch (err) {
        return errorResponse(res, err);
    }
}

exports.deleteExecutivesHistory = async (req, res) => {
    try {
        await executivesHistoryService.deleteExecutivesHistoryService(req);
        return messageSuccessResponse(res, 'Success delete executives history');
    } catch (err) {
        return errorResponse(res, err);
    }
};