package com.sqx.modules.activity.controller;

import com.sqx.common.query.PageQuery;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.activity.dto.JoinActivityDTO;
import com.sqx.modules.activity.dto.QuitActivityDTO;
import com.sqx.modules.activity.service.ActivityShopService;
import com.sqx.modules.activity.vo.ShopActivityVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 活动商家
 * @author : codingliang
 * @date : 2024-6-17
 */
@Api(tags = "活动-活动商家管理")
@RestController
@RequestMapping("admin/activity-shop")
@RequiredArgsConstructor
public class ActivityShopController{

    private final ActivityShopService activityShopService;

    @ApiOperation("活动参与的商家列表")
    @GetMapping("activity-shop-page/{activityId}")
    public Result getActivityShopPage(@PathVariable @ApiParam("活动id") Long activityId, PageQuery queryDTO) {
        PageUtils page = activityShopService.getShopByActivityId(activityId, queryDTO);
        return Result.success().put("data", page);
    }

    @ApiOperation(value = "商家参与活动列表", response = ShopActivityVO.class)
    @GetMapping("shop-activity-list/{shopId}")
    public Result getShopActivityPage(@PathVariable @ApiParam("商家id") Long shopId) {
        List<ShopActivityVO> shopActivityVOList = activityShopService.getActivityByShopIds(Arrays.asList(shopId));
        return Result.success().put("data", shopActivityVOList);
    }

     @ApiOperation(value = "商家加入活动", response = List.class)
     @PostMapping("join")
     public Result joinActivity(@RequestBody @Valid JoinActivityDTO dto) {
         List<Long> ids = activityShopService.joinActivity(dto);
         return Result.success().put("data", ids);
     }

     @ApiOperation("商家退出活动(根据活动id和店铺id退出)")
     @PutMapping("quit")
     public Result quitActivity(@Valid QuitActivityDTO dto) {
         activityShopService.quitActivity(dto);
         return Result.success();
     }

    @ApiOperation("商家退出活动(根据参与id退出)")
    @PutMapping("quit-by-id/{activityShopId}")
    public Result quitByActivityShopId(@PathVariable @ApiParam("活动店铺id") Long activityShopId) {
        activityShopService.quitByActivityShopId(activityShopId);
        return Result.success();
    }
}
