package com.erp.service;

import com.erp.common.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;

@Service
public class OpenApiProxyService extends BaseService {

    @Autowired private CommonService commonService;

    public Map<String, Object> getOpenApiProxyList(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        commonService.applyPagination(params);
        Number cntNum = sqlSession.selectOne("openApiProxy.getOpenApiProxyListCnt", params);
        int totalCount = cntNum != null ? cntNum.intValue() : 0;
        List<Map<String, Object>> list = sqlSession.selectList("openApiProxy.getOpenApiProxyList", params);
        return commonService.buildListResponse(list, totalCount, params);
    }

    public Map<String, Object> getOpenApiProxyInfo(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        return sqlSession.selectOne("openApiProxy.getOpenApiProxyInfo", params);
    }

    @Transactional
    public int insertOpenApiProxy(Map<String, Object> params) {
        return sqlSession.insert("openApiProxy.insertOpenApiProxy", params);
    }

    @Transactional
    public int updateOpenApiProxy(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        return sqlSession.update("openApiProxy.updateOpenApiProxy", params);
    }

    @Transactional
    public int deleteOpenApiProxy(Map<String, Object> params) {
        commonService.applyCompanyCodeFilter(params);
        return sqlSession.delete("openApiProxy.deleteOpenApiProxy", params);
    }
}
