package com.yida.data.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.system.EduApp;
import com.yida.data.common.core.entity.system.EduAppTemplate;
import com.yida.data.common.core.entity.system.EduQywxServiceProvider;
import com.yida.data.system.service.EduAppService;

import com.yida.data.system.service.EduAppTemplateService;
import com.yida.data.system.service.EduQywxServiceProviderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;

@Api(tags = "企业微信 应用管理(不鉴权)")
@RestController
@RequestMapping("/in/app")
@RequiredArgsConstructor
public class InEduAppController {
    private final EduAppService eduAppService;
    private final EduAppTemplateService eduAppTemplateService;
    private final EduQywxServiceProviderService eduQywxServiceProviderService;

    @GetMapping("/getAppBySchoolOrCorpIdAndCode")
    public ResultBean<EduApp> getAppBySchoolOrCorpIdAndCode(Long schoolId, String corpId, String code) {
        return ResultBean.buildSuccess(eduAppService.getAppBySchoolOrCorpIdAndCode(schoolId, corpId, code));
    }

    @GetMapping("/getAppTemplateByTemplateId")
    public ResultBean<EduAppTemplate> getAppTemplateByTemplateId(String templateId, String serviceCorpId) {
        return ResultBean.buildSuccess(eduAppTemplateService.getOne(Wrappers.lambdaQuery(new EduAppTemplate())
                .eq(EduAppTemplate::getTemplateId, templateId)
                .eq(EduAppTemplate::getServiceCorpId, serviceCorpId)
        ));
    }

    @GetMapping("/getServiceProviderByServiceCorpId")
    public ResultBean<EduQywxServiceProvider> getServiceProviderByServiceCorpId(String serviceCorpId) {
        return ResultBean.buildSuccess(eduQywxServiceProviderService.getOne(Wrappers.lambdaQuery(new EduQywxServiceProvider())
                .eq(EduQywxServiceProvider::getCorpId, serviceCorpId)
        ));
    }
}
