package com.sz.admin.monitor.controller;

import com.sz.admin.monitor.pojo.dto.facelibrary.FaceLibraryCreateDTO;
import com.sz.admin.monitor.pojo.dto.facelibrary.FaceLibraryListDTO;
import com.sz.admin.monitor.pojo.dto.facelibrary.FaceLibraryUpdateDTO;
import com.sz.admin.monitor.pojo.vo.facelibrary.FaceLibraryVO;
import com.sz.admin.monitor.service.FaceLibraryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import com.sz.core.common.entity.ApiPageResult;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.common.constant.GlobalConstant;
import com.sz.core.common.entity.PageResult;
import com.sz.core.common.entity.SelectIdsDTO;
import com.sz.core.common.entity.ImportExcelDTO;
import jakarta.servlet.http.HttpServletResponse;

/**
 * <p>
 * 人脸库表 Controller
 * </p>
 *
 * @author Lz
 * @since 2026-02-26
 */
@Tag(name =  "人脸库表")
@RestController
@RequestMapping("ry-face-library")
@RequiredArgsConstructor
public class FaceLibraryController  {

    private final FaceLibraryService faceLibraryService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "ry.face.library.create")
    @PostMapping
    public ApiResult<Void> create(@RequestBody FaceLibraryCreateDTO dto) {
        faceLibraryService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "ry.face.library.update")
    @PutMapping
    public ApiResult<Void> update(@RequestBody FaceLibraryUpdateDTO dto) {
        faceLibraryService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @SaCheckPermission(value = "ry.face.library.remove")
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        faceLibraryService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "ry.face.library.query_table")
    @GetMapping
    public ApiResult<PageResult<FaceLibraryVO>> list(FaceLibraryListDTO dto) {
        return ApiPageResult.success(faceLibraryService.page(dto));
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "ry.face.library.query_table")
    @GetMapping("/{id}")
    public ApiResult<FaceLibraryVO> detail(@PathVariable Object id) {
        return ApiResult.success(faceLibraryService.detail(id));
    }

    @Operation(summary = "导入")
    @Parameters({
        @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "ry.face.library.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        faceLibraryService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "ry.face.library.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody FaceLibraryListDTO dto, HttpServletResponse response) {
        faceLibraryService.exportExcel(dto, response);
    }
}