package com.seer.teach.mp.app.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.app.controller.req.AppMpDealerApplyQueryReq;
import com.seer.teach.mp.enums.ApplicationTypeEnum;
import com.seer.teach.mp.request.DealerApplyReq;
import com.seer.teach.mp.app.controller.resp.AppMpDealerApplyResp;
import com.seer.teach.mp.app.service.AppDealerApplicationsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

/**
 * <p>
 * 租户表 前端控制器
 * </p>
 *
 * @author Wang
 * @since 2025-08-01 19:39:18
 */
@Tag(name = "APP - 经销商申请")
@RestController
@RequestMapping("/app/dealer")
@LogPrint
@EncryptionAnnotation
@DecryptionAnnotation
public class AppDealerApplicationsController {

    @Resource
    private AppDealerApplicationsService appDealerApplicationsService;

    /**
     * 经销商申请接口
     */
    @Operation(summary = "申请成为经销商")
    @PostMapping("/apply")
    @SaCheckPermission("mp:app:dealer:apply")
    public ResultBean<String> applyForDealer(@ModelAttribute DealerApplyReq request) {
        request.setApplyType(ApplicationTypeEnum.DISTRIBUTOR.getCode());
        appDealerApplicationsService.applyForDealer(request,StpUtil.getLoginIdAsInt());
        return ResultBean.success("申请已提交，请等待审核");
    }

    /**
     * 更新经销商申请信息
     */
    @Operation(summary = "更新经销商申请信息")
    @PutMapping("/apply/update")
    @SaCheckPermission("mp:app:dealer:apply-update")
    public ResultBean<Boolean> updateDealerApplication(@ModelAttribute DealerApplyReq request) {
        return ResultBean.success(appDealerApplicationsService.updateDealerApplication(request,StpUtil.getLoginIdAsInt()));
    }

    /**
     * 查询经销商信息
     */
    @Operation(summary = "查询经销商信息")
    @PostMapping("/info")
    @SaCheckPermission("mp:app:dealer:apply-info")
    @DecryptionAnnotation
    @EncryptionAnnotation
    public ResultBean<AppMpDealerApplyResp> info() {
        return ResultBean.success(appDealerApplicationsService.info(StpUtil.getLoginIdAsInt()));
    }


    /**
     * 查询经经销商申请列表
     */
    @Operation(summary = "查询经销商信息")
    @PostMapping("/apply/paged")
    @SaCheckPermission("mp:app:dealer:apply-paged")
    @DecryptionAnnotation
    @EncryptionAnnotation
    public ResultBean<PageListBean<AppMpDealerApplyResp>> page(@RequestBody AppMpDealerApplyQueryReq pageReq) {
        return ResultBean.success(appDealerApplicationsService.page(StpUtil.getLoginIdAsInt(),pageReq));
    }
}