package com.zt.plat.module.base.controller.admin.materialgradeext;

import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
import com.zt.plat.framework.datapermission.core.annotation.CompanyDataPermissionIgnore;
import com.zt.plat.framework.datapermission.core.annotation.DeptDataPermissionIgnore;
import com.zt.plat.module.base.controller.admin.materialgradeext.vo.MaterialGradeExtPageReqVO;
import com.zt.plat.module.base.controller.admin.materialgradeext.vo.MaterialGradeExtRespVO;
import com.zt.plat.module.base.controller.admin.materialgradeext.vo.MaterialGradeExtSaveReqVO;
import com.zt.plat.module.base.service.materialgradeext.MaterialGradeExtService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.zt.plat.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 物料牌号扩展")
@RestController
@RequestMapping("/base/material-grade-ext")
@Validated
@CompanyDataPermissionIgnore
@DeptDataPermissionIgnore
public class MaterialGradeExtController {

    @Resource
    private MaterialGradeExtService materialGradeExtService;

    @PostMapping("/create")
    @Operation(summary = "创建物料牌号扩展")
    @PreAuthorize("@ss.hasPermission('base:material-grade-ext:create')")
    public CommonResult<MaterialGradeExtRespVO> create(@Valid @RequestBody MaterialGradeExtSaveReqVO reqVO) {
        return success(materialGradeExtService.create(reqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新物料牌号扩展")
    @PreAuthorize("@ss.hasPermission('base:material-grade-ext:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody MaterialGradeExtSaveReqVO reqVO) {
        materialGradeExtService.update(reqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除物料牌号扩展")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:material-grade-ext:delete')")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        materialGradeExtService.delete(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Operation(summary = "批量删除物料牌号扩展")
    @PreAuthorize("@ss.hasPermission('base:material-grade-ext:delete')")
    public CommonResult<Boolean> deleteList(@RequestBody BatchDeleteReqVO req) {
        materialGradeExtService.deleteByIds(req.getIds());
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得物料牌号扩展")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:material-grade-ext:query')")
    public CommonResult<MaterialGradeExtRespVO> get(@RequestParam("id") Long id) {
        return success(materialGradeExtService.get(id));
    }

    @RequestMapping(value = "/page", method = {RequestMethod.GET, RequestMethod.POST})
    @Operation(summary = "获得物料牌号扩展分页")
    @PreAuthorize("@ss.hasPermission('base:material-grade-ext:query')")
    public CommonResult<PageResult<MaterialGradeExtRespVO>> getPage(@Valid @RequestBody(required = false) MaterialGradeExtPageReqVO pageReqVO) {
        if (pageReqVO == null) {
            pageReqVO = new MaterialGradeExtPageReqVO();
        }
        return success(materialGradeExtService.getPage(pageReqVO));
    }
}