import express from 'express';
import { companySystem } from '../../../../features/company';
import { ChatSystem } from '../../../../features/chat';
import { LogSystem } from '../../../../core/log';
import { ChatColors } from '../../../../const/chat-colors';

export async function SetCompanyType(req: express.Request, res: express.Response) {
    const by = req.body.by;
    const companyId = Number(req.body.companyId);
    const typeId = Number(req.body.typeId);
    const typeName = req.body.typeName;

    const company = companySystem.getCompanyById(companyId);

    if (!company) {
        res.sendStatus(404);
        return;
    }

    company.type = typeId;

    LogSystem.CompanyEvent(company, 'set_company', `<Web> ${by} set company ${company.id}, ${company.name} type to ${typeId},${typeName}`);
    ChatSystem.AdminWarn(`<Web> ${by} set company ${company.id}, ${company.name} type to ${typeId},${typeName}`, 'account.admin.setcompany');

    res.sendStatus(200);
}
