package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.OMRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.OMRecordForm;
import com.youlai.boot.system.model.query.OMRecordQuery;
import com.youlai.boot.system.model.vo.OMRecordVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 运维管理前端控制层
 *
 * @author kangyu
 * @since 2025-07-25 10:18
 */
@Tag(name = "运维管理接口")
@RestController
@RequestMapping("/api/v1/oMRecords")
@RequiredArgsConstructor
public class OMRecordController  {

    private final OMRecordService oMRecordService;

    @Operation(summary = "运维管理分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:oMRecord:query')")
    public PageResult<OMRecordVO> getOMRecordPage(OMRecordQuery queryParams ) {
        IPage<OMRecordVO> result = oMRecordService.getOMRecordPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增运维管理")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:oMRecord:add')")
    public Result<Void> saveOMRecord(@RequestBody @Valid OMRecordForm formData ) {
        boolean result = oMRecordService.saveOMRecord(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取运维管理表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:oMRecord:edit')")
    public Result<OMRecordForm> getOMRecordForm(
        @Parameter(description = "运维管理ID") @PathVariable Long id
    ) {
        OMRecordForm formData = oMRecordService.getOMRecordFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改运维管理")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:oMRecord:edit')")
    public Result<Void> updateOMRecord(
            @Parameter(description = "运维管理ID") @PathVariable Long id,
            @RequestBody @Validated OMRecordForm formData
    ) {
        boolean result = oMRecordService.updateOMRecord(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除运维管理")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:oMRecord:delete')")
    public Result<Void> deleteOMRecords(
        @Parameter(description = "运维管理ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = oMRecordService.deleteOMRecords(ids);
        return Result.judge(result);
    }
}
