package com.yonge.cooleshow.teacher.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.service.TenantAlbumMusicService;
import com.yonge.cooleshow.biz.dal.service.TenantGroupAlbumService;
import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumMusicWrapper;
import com.yonge.cooleshow.biz.dal.wrapper.TenantGroupAlbumWrapper;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.yonge.cooleshow.common.controller.BaseController.failed;

@Slf4j
@Validated
@RestController
@RequestMapping("${app-config.url.teacher:}/tenantGroupAlbum")
@Api(tags = "机构小组专辑配置表")
public class TenantGroupAlbumController {

    @Autowired
    private TenantGroupAlbumService tenantGroupAlbumService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private TenantAlbumMusicService tenantAlbumMusicService;
	@ApiOperation(value = "学生可购买机构专辑信息")
	@GetMapping("/buyAlbumInfo")
	public HttpResponseResult<List<TenantGroupAlbumWrapper.BuyTenantAlbum>> buyAlbumInfo(@RequestParam(required = false) Long tenantGroupAlbumId) {

        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return HttpResponseResult.failed(HttpStatus.FORBIDDEN, "请登录");
        }

        TenantGroupAlbumWrapper.BuyTenantAlbumQuery query = new TenantGroupAlbumWrapper.BuyTenantAlbumQuery();
        query.setTenantGroupAlbumId(tenantGroupAlbumId);
        query.setUserId(user.getId());
        query.setClientType(ClientEnum.TEACHER);
		return HttpResponseResult.succeed(tenantGroupAlbumService.buyAlbumInfo(query));
	}

    @ApiOperation(value = "查询条件")
    @PostMapping("/selectCondition")
    public HttpResponseResult<TenantAlbumMusicWrapper.TenantAlbumMusicSelectData> selectCondition(@RequestBody @Validated TenantAlbumMusicWrapper.TenantAlbumMusicSelect query) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
//        query.setUserId(user.getId());
        return HttpResponseResult.succeed(tenantAlbumMusicService.getTenantAlbumMusicQuery(query));
    }

}