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.school.EduYidaAppAccount;
import com.yida.data.system.service.EduAppAccountService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "易达app订阅号")
@RestController
@RequestMapping("/yida/account")
@RequiredArgsConstructor
public class EduYidaAppAccountController {
    private final EduAppAccountService eduAppAccountService;

    @ApiOperation("根据订阅号id查询订阅号")
    @GetMapping("/getAccountByAccountId")
    public ResultBean getAccountByAccountId(String accountId) {
        return ResultBean.buildSuccess(eduAppAccountService.getOne(Wrappers.lambdaQuery(new EduYidaAppAccount())
                .eq(EduYidaAppAccount::getYidaAppAccountId, accountId)));
    }

    @ApiOperation("根据学校id与类型查询订阅号")
    @GetMapping("/getAccountByType")
    ResultBean<EduYidaAppAccount> getAccountByType(@RequestParam("schoolId") Long schoolId,
                                                   @ApiParam("0-家长，1-老师") @RequestParam("type") Integer type) {
        return ResultBean.buildSuccess(eduAppAccountService.getOne(Wrappers.lambdaQuery(new EduYidaAppAccount())
                .eq(EduYidaAppAccount::getSchoolId, schoolId)
                .eq(EduYidaAppAccount::getType, type)));
    }
}
