package com.changhu.module.miniProgram.controller;

import com.changhu.common.annotation.CheckUserType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.db.enums.UserType;
import com.changhu.module.miniProgram.pojo.params.SaveOrUpdateSecurityUserParams;
import com.changhu.module.miniProgram.pojo.vo.IndexServiceProjectListVo;
import com.changhu.module.miniProgram.service.ProjectManageIndexService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 20252
 * @createTime 2024/9/10 下午3:48
 * @desc 项目经理首页控制器
 */
@Tag(name = "项目经理首页")
@JsonBody
@RequestMapping("/projectManageIndex")
public class ProjectManageIndexController {

    @Autowired
    private ProjectManageIndexService projectManageIndexService;

    @Operation(summary = "获取我的服务项目")
    @GetMapping("/getMyServiceProject")
    @CheckUserType(userTypes = UserType.MINI_PROGRAM_PROJECT_MANAGE)
    public List<IndexServiceProjectListVo> getMyServiceProjectList() {
        return projectManageIndexService.getMyServiceProjectList();
    }

    @Operation(summary = "根据id删除保安人员")
    @DeleteMapping("/deleteSecurityUserByServiceProjectId")
    public void deleteSecurityUserById(@RequestParam @Schema(description = "保安人员id") Long securityUserId) {
        projectManageIndexService.deleteSecurityUserByServiceProjectId(securityUserId);
    }

    @Operation(summary = "保存或更新保安人员")
    @PostMapping("/saveOrUpdateSecurityUser")
    public void saveOrUpdateSecurityUser(@RequestBody @Valid SaveOrUpdateSecurityUserParams params) {
        projectManageIndexService.saveOrUpdateSecurityUser(params);
    }

    @JsonBody(value = false)
    @Operation(summary = "获取表单分享二维码")
    @GetMapping(value = "/shareForm_QR_Code")
    public ResponseEntity<Resource> shareForm_QR_Code(@Schema(description = "要生成的路径") @RequestParam String path,
                                                      @Schema(description = "生成二维码的宽度") @RequestParam(defaultValue = "430") Integer width) {
        return projectManageIndexService.shareForm_QR_Code(path, width);
    }
}
