package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.store.service.LifeUserBrandedCardService;

import java.text.ParseException;
import java.util.Map;

@Api(tags = {"一期-用户联名卡"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/userbrandedcard")
@RequiredArgsConstructor
public class UserBrandedCardController {

    private final LifeUserBrandedCardService userBrandedCardService;

    @ApiOperation("联名卡列表")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页页数", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "size", value = "分页条数", dataType = "String", paramType = "query", required = true)})
    @GetMapping("/getBrandedCardList")
    private R<IPage<Map<String, Object>>> getBrandedCardList(@RequestParam(value = "page", defaultValue = "1") int page,
                                                             @RequestParam(value = "size", defaultValue = "10") int size) {
        log.info("LifeBrandedCardController.getBrandedCardList?page={},size={}", page, size);
        return R.data(userBrandedCardService.getBrandedCardList(page, size));
    }

    @ApiOperation("联名卡详情")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "cardId", value = "cardId", dataType = "String", paramType = "query")})
    @GetMapping("/getBrandedCardDetail")
    private R<Map<String, Object>> getBrandedCardDetail(@RequestParam("cardId") String cardId) {
        log.info("LifeBrandedCardController.getBrandedCardDetail?cardId={}", cardId);
        return R.data(userBrandedCardService.getBrandedCardDetail(cardId));
    }

    @ApiOperation("购买联名卡前检查")
    @ApiOperationSupport(order = 3)
    @ApiImplicitParams({@ApiImplicitParam(name = "cardId", value = "cardId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query")})

    @GetMapping("/buyBrandedCardCheck")
    private R<Map<String, Object>> buyBrandedCardCheck(@RequestParam("cardId") String cardId,
                                                       @RequestParam("userId") String userId) throws ParseException {
        log.info("LifeBrandedCardController.buyBrandedCardCheck?cardId={},userId={}", cardId, userId);
        return R.data(userBrandedCardService.buyBrandedCardCheck(cardId, userId));
    }

    @ApiOperation("购买联名卡成功后调用")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({@ApiImplicitParam(name = "cardId", value = "cardId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query")})
    @GetMapping("/buyBrandedCard")
    private R<Map<String, Object>> buyBrandedCard(@RequestParam("cardId") String cardId,
                                                  @RequestParam("userId") String userId) {
        log.info("LifeBrandedCardController.buyBrandedCard?cardId={},userId={}", cardId, userId);
        return R.data(userBrandedCardService.buyBrandedCard(cardId, userId));
    }
}
