package com.ruoyi.xq.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageModel;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.xq.domain.ActivityOrder;
import com.ruoyi.xq.domain.Group;
import com.ruoyi.xq.domain.GroupOrder;
import com.ruoyi.xq.dto.app.activity.ActivityShopAppInfo;
import com.ruoyi.xq.dto.app.activity.CreateOrderReq;
import com.ruoyi.xq.dto.app.group.CreateGroupOrderReq;
import com.ruoyi.xq.dto.app.group.GroupInfoAppVo;
import com.ruoyi.xq.dto.app.group.GroupListAppVo;
import com.ruoyi.xq.dto.app.group.GroupQuery;
import com.ruoyi.xq.dto.app.pay.OrderCreateVo;
import com.ruoyi.xq.dto.app.user.HomePageReq;
import com.ruoyi.xq.dto.app.user.vo.HomeUserListVo;
import com.ruoyi.xq.service.GroupOrderService;
import com.ruoyi.xq.service.GroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 相亲群
 *
 * @author 77
 * @date 2024-05-15
 */

@RestController
@RequestMapping("/api/group")
@Tag(name = "相亲群相关接口")
public class GroupAppController extends BaseController {
    @Autowired
    private GroupService groupService;
    @Autowired
    private GroupOrderService groupOrderService;

    @GetMapping("/page")
    @Operation(summary = "相亲群查询-分页")
    @Log(title = "相亲群查询-分页", businessType = BusinessType.OTHER, isPrintResponseData = false,isSaveDb = false)
    public R<PageModel<GroupListAppVo>> groupPage(PageQuery pageQuery, GroupQuery groupQuery){
        Page<GroupListAppVo> vo = groupService.pageApp(pageQuery, groupQuery);
        return R.ok(PageModel.build(vo));
    }

    @GetMapping("/info")
    @Operation(summary = "相亲群详情")
    @Log(title = "相亲群详情", businessType = BusinessType.OTHER, isPrintResponseData = false, isSaveDb = false)
    @SaIgnore
    public R<GroupInfoAppVo> info(Long groupId){
        if(groupId == null){
            return R.ok();
        }
        GroupInfoAppVo info = groupService.info(groupId);
        return R.ok(info);
    }

    @PostMapping("/create/order")
    @Operation(summary = "创建相亲群订单")
    @Log(title = "创建相亲群订单", businessType = BusinessType.OTHER)
    public R<OrderCreateVo> createOrder(@RequestBody CreateGroupOrderReq req){
        Long userId = LoginHelper.getUserId();
        req.setUserId(userId);
        GroupOrder order = groupOrderService.createOrder(req);
        OrderCreateVo result = new OrderCreateVo();
        result.setPrice(order.getJoinPrice());
        result.setOrderNo(order.getOrderNo());
        result.setOrderName(order.getOrderName());
        return R.ok(result);
    }

}
