/*
 * @Author: Kane
 * @Date: 2023-03-02 14:48:35
 * @LastEditors: Kane
 * @FilePath: /task_schedule/src/utils/account.ts
 * @Description:
 *
 * Copyright (c) ${2022} by Kane, All Rights Reserved.
 */
import { type AxiosResponse } from "axios";
import { service as instance } from "./api/request.js";
import { API_URL } from "./api/config.js";
import { cleanStaffInfo, clearCallerInfo } from "./api/localStorage.js";

// @ts-expect-error 之后再补充类型文件
import { router } from "../router/index.js";
// declare const require: any;
// const { router, } = require( "../router/index.js" );

interface LoginInfo
{
    p13account: string;
    password: string;
}

async function login( data: LoginInfo ): Promise<AxiosResponse<any, any>>
{
    return await instance.request(
        {
            method: "post",
            url: API_URL.URL_LOGIN,
            data,
        }
    );
}

function logout(): void
{
    cleanStaffInfo();
    clearCallerInfo();

    void router.push( "/login" );
}

export { type LoginInfo, login, logout };
