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 SetCompanyName(req: express.Request, res: express.Response) {
    const by = req.body.by;
    const companyId = Number(req.body.companyId);
    const name = req.body.name;

    const company = companySystem.getCompanyById(companyId);

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

    const elderName = company.name;

    company.name = name;

    LogSystem.CompanyEvent(company, 'set_company', `<Web> ${by} renamed company #${company.id} from "${elderName}" to "${company.name}"`);

    ChatSystem.AdminWarn(`<Web> ${by} renamed company #${company.id} from "${elderName}" to "${company.name}"`, 'account.admin.setcompany');

    res.sendStatus(200);
}
