import axios from "axios";
import { getSysAdminNonce } from "../helpers/GetSysAdminNonce";
import { getPayload } from "../helpers/GetPayload";
import { getApiHost } from "../helpers/GetApiHost";
import {
    PaginateCompaniesParams,
    PaginateCompaniesResults,
    SetCompanyBannedParams,
    UpdateCompanyParams,
} from "../models/Companies.Model";

export const paginateCompanies = async (params: PaginateCompaniesParams): Promise<PaginateCompaniesResults> => {
    const nonce = await getSysAdminNonce();
    const result = await axios.post(`${getApiHost()}/sysadmin/companies/paginate`, {
        ...params,
        payload: getPayload(nonce),
    });
    return result.data;
};

export const updateCompany = async (params: UpdateCompanyParams): Promise<any> => {
    const nonce = await getSysAdminNonce();
    const result = await axios.post(`${getApiHost()}/sysadmin/companies/update`, {
        ...params,
        payload: getPayload(nonce),
    });
    return result.data;
};

export const setCompanyBanned = async (params: SetCompanyBannedParams): Promise<any> => {
    const nonce = await getSysAdminNonce();
    const result = await axios.post(`${getApiHost()}/sysadmin/companies/set-banned`, {
        ...params,
        payload: getPayload(nonce),
    });
    return result.data;
};
