package com.yonge.cooleshow.tenant.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.TenantGroupAlbumService;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

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

    @Autowired
    private TenantGroupAlbumService tenantGroupAlbumService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

	@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.TENANT);
    
		return HttpResponseResult.succeed(tenantGroupAlbumService.buyAlbumInfo(query));
	}
}