package com.zhongshu.card.server.core.controller.projectAbout;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.base.ProjectOidParam;
import com.zhongshu.card.client.model.projectAbout.*;
import com.zhongshu.card.client.model.school.CardInfoPoolModel;
import com.zhongshu.card.client.model.school.CardInfoSearch;
import com.zhongshu.card.server.core.service.projectAbout.ProjectExcelTemplateService;
import com.zhongshu.card.server.core.service.projectAbout.ProjectIotInfoService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 平台的 excel模版 配置
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/excelTemplate")
@Tag(name = "平台-excel模版")
public class ProjectExcelTemplateController {

    @Autowired
    ProjectExcelTemplateService projectExcelTemplateService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存信息（添加、编辑）", description = "保存信息")
    @RequestMapping(value = "saveExcelTemplate", method = {RequestMethod.POST})
    public ResultContent saveExcelTemplate(@RequestBody @Valid ProjectExcelTemplateParam param) {
        return projectExcelTemplateService.saveExcelTemplate(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "列表列表-分页查询）", description = "列表列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<ProjectExcelTemplateModel>> page(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) ProjectExcelTemplateSearch param) {
        return projectExcelTemplateService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除数据", description = "删除数据")
    @RequestMapping(value = "deleteData", method = {RequestMethod.POST})
    public ResultContent deleteData(@RequestBody @Valid IDParam param) {
        return projectExcelTemplateService.deleteData(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到详情", description = "得到详情")
    @RequestMapping(value = "getDetail", method = {RequestMethod.POST})
    public ResultContent getDetail(@RequestBody @Valid IDParam param) {
        return projectExcelTemplateService.getDetail(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "根据标记得到模版数据", description = "根据标记得到模版数据")
    @RequestMapping(value = "getDetailByMark", method = {RequestMethod.POST})
    public ResultContent<ProjectExcelTemplateModel> getDetailByMark(@RequestBody @Valid ProjectExcelTemplateQuery param) {
        return projectExcelTemplateService.getDetailByMark(param);
    }

}
