/**
 * @Author: Kane Wang <wangkane@qq.com>
 * @Date: 2026-01-05 10:42:42
 * @LastEditors: Kane Wang
 * @LastModified: 2026-02-04 15:37:20
 * @FilePath: src/utils/regulatory_utils.ts
 * @Description:
 *
 *               Copyright (c) 2025 by Kane All rights reserved
 */
import { service } from "@/utils/api/request.ts";
import { API_URL } from "@/utils/config.ts";
import { type RegulatoryData, type RegulatoryFile } from "@/types/regulatory/regulatory.ts";

interface AddNewRegulatoryResponse
{
    success: boolean;
    message: string;
}

interface Render {
    ( resonse: AddNewRegulatoryResponse ) :void, }

type CallBackRender = ( response: AddNewRegulatoryResponse ) => void;
/**
 *
 * @param regulatory RegulatoryData类型制度对象，用于发送请求。
 * @param render 回调函数，请求成功后调用。
 */
function addNewRegulatory( regulatory: RegulatoryData, render: Render ): void
{
    // const url = API_URL.URL_ADD_NEW_REGULATORY;

    // 响应对象
    const resp: AddNewRegulatoryResponse = {
        success: false,
        message: "",
    };

    service.request({
        method:"post",
        url: API_URL.URL_ADD_NEW_REGULATORY,
        data: regulatory,
    })
        .then(( response ):void=>
        {
            const data = response.data ?? {};

            resp.success = data.success ?? false;
            resp.message = data.message ?? "服务器没有返回调用结果消息，请检查日志！";

            if ( render !== undefined )
            {
                render( resp );
            }
        })
        .catch(( error ): void=>
        {
            resp.success = false;
            resp.message = String( error );

            if ( render !== undefined )
            {
                render( resp );
            }
        });
}

export {
    addNewRegulatory,
    type AddNewRegulatoryResponse,
    type Render,
    type CallBackRender
};