package com.multictrl.modules.business.controller;

import com.multictrl.common.annotation.ApiOrder;
import com.multictrl.common.annotation.LogOperation;
import com.multictrl.common.constant.Constant;
import com.multictrl.common.page.PageData;
import com.multictrl.common.utils.Result;
import com.multictrl.common.validator.AssertUtils;
import com.multictrl.common.validator.ValidatorUtils;
import com.multictrl.modules.business.dto.GeoMarkDTO;
import com.multictrl.modules.business.service.GeoMarkService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 地图标注
 *
 * @author Sdy
 * @since 1.0.0 2026-05-25
 */
@RestController
@RequestMapping("business/mark")
@Tag(name = "地图标注")
@ApiOrder(12)
@RequiredArgsConstructor
public class GeoMarkController {
    private final GeoMarkService geoMarkService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @Parameters({
            @Parameter(name = Constant.PAGE, description = "当前页码，从1开始"),
            @Parameter(name = Constant.LIMIT, description = "每页显示记录数"),
            @Parameter(name = "dockSn", description = "设备编号"),
            @Parameter(name = "markType", description = "标注类型"),
            @Parameter(name = "markName", description = "标注名称"),
            @Parameter(name = "showAll", description = "是否展示全局", example = "字符串:true")
    })
    @RequiresPermissions("bus:mark:page")
    public Result<PageData<GeoMarkDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
        PageData<GeoMarkDTO> page = geoMarkService.pageList(params);

        return new Result<PageData<GeoMarkDTO>>().ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @RequiresPermissions("bus:mark:info")
    public Result<GeoMarkDTO> get(@PathVariable("id") Long id) {
        GeoMarkDTO data = geoMarkService.getDetail(id);

        return new Result<GeoMarkDTO>().ok(data);
    }

    @PostMapping
    @Operation(summary = "保存")
    @LogOperation("保存")
    @RequiresPermissions("bus:mark:save")
    public Result<Object> save(@RequestBody GeoMarkDTO dto) {
        //效验数据
        ValidatorUtils.validateEntity(dto);
        geoMarkService.save(dto);

        return new Result<>();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @LogOperation("删除")
    @RequiresPermissions("bus:mark:delete")
    public Result<Object> delete(@RequestBody Long[] ids) {
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        geoMarkService.delete(ids);

        return new Result<>();
    }

}
