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

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mp.admin.controller.req.AgentEmployeeRelationQueryReq;
import com.seer.teach.mp.admin.controller.req.AgentEmployeeRelationReq;
import com.seer.teach.mp.admin.controller.req.AgentEmployeeSaveReq;
import com.seer.teach.mp.admin.controller.resp.AgentEmployeeRelationResp;
import com.seer.teach.mp.admin.service.IAdminAgentEmployeeRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@LogPrint
@RequiredArgsConstructor
@RestController
@Tag(name = "管理端 - 代理商员工")
@RequestMapping("/mp/agent/employee")
public class AdminAgentEmployeeRelationController {

    private final IAdminAgentEmployeeRelationService agentEmployeeRelationService;

    @Operation(summary = "代理商员工关联列表")
    @PostMapping("/page-list")
    @SaCheckPermission("mp:admin:agent:employee:list")
    public ResultBean<PageListBean<AgentEmployeeRelationResp>> pageList(@RequestBody @Validated AgentEmployeeRelationQueryReq query) {
        return ResultBean.success(agentEmployeeRelationService.pageList(query));
    }

    @Operation(summary = "新增代理商员工关联")
    @PostMapping("/save")
    @SaCheckPermission("mp:admin:agent:employee:save")
    public ResultBean<Boolean> save(@RequestBody @Validated AgentEmployeeSaveReq request) {
        return ResultBean.success(agentEmployeeRelationService.save(request));
    }

    @Operation(summary = "更新代理商员工关联")
    @PostMapping("/update")
    @SaCheckPermission("mp:admin:agent:employee:update")
    public ResultBean<Boolean> update(@RequestBody @Validated AgentEmployeeRelationReq request) {
        return ResultBean.success(agentEmployeeRelationService.saveOrUpdateRelation(request));
    }

    @Operation(summary = "删除代理商员工关联")
    @DeleteMapping("/{id}")
    @SaCheckPermission("mp:admin:agent:employee:delete")
    public ResultBean<Boolean> delete(@PathVariable Integer id) {
        return ResultBean.success(agentEmployeeRelationService.deleteRelation(id));
    }

    @Operation(summary = "详情")
    @GetMapping("/{id}")
    @SaCheckPermission("mp:admin:agent:employee:get")
    public ResultBean<AgentEmployeeRelationResp> get(@PathVariable Integer id) {
        AgentEmployeeRelationResp result = agentEmployeeRelationService.getById(id);
        return ResultBean.success(result);
    }

    @Operation(summary = "根据代理商ID获取员工列表")
    @GetMapping("/by-agent/{agentId}")
    @SaCheckPermission("mp:admin:agent:employee:by-agent")
    public ResultBean<java.util.List<AgentEmployeeRelationResp>> getByAgent(@PathVariable Integer agentId) {
        return ResultBean.success(agentEmployeeRelationService.getEmployeeRelationsByAgentId(agentId));
    }
}