package cn.iocoder.lyzsys.module.tjt.controller.admin.office;

import cn.iocoder.lyzsys.framework.common.pojo.CommonResult;
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
import cn.iocoder.lyzsys.module.tjt.controller.admin.office.vo.OfficePageReqVO;
import cn.iocoder.lyzsys.module.tjt.controller.admin.office.vo.OfficeRespVO;
import cn.iocoder.lyzsys.module.tjt.controller.admin.office.vo.OfficeSaveReqVO;
import cn.iocoder.lyzsys.module.tjt.controller.admin.office.vo.OfficeSimpleRespVO;
import cn.iocoder.lyzsys.module.tjt.service.office.OfficeService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.lyzsys.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 专业所")
@RestController
@RequestMapping("/tjt/office")
@Validated
public class OfficeController {

    @Resource
    private OfficeService officeService;

    @PostMapping("/create")
    @Operation(summary = "创建专业所")
    @PreAuthorize("@ss.hasPermission('tjt:office:create')")
    public CommonResult<Long> createOffice(@Valid @RequestBody OfficeSaveReqVO createReqVO) {
        return success(officeService.createOffice(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "修改专业所")
    @PreAuthorize("@ss.hasPermission('tjt:office:update')")
    public CommonResult<Boolean> updateOffice(@Valid @RequestBody OfficeSaveReqVO updateReqVO) {
        officeService.updateOffice(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除专业所")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:office:delete')")
    public CommonResult<Boolean> deleteOffice(@RequestParam("id") Long id) {
        officeService.deleteOffice(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得专业所详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:office:query')")
    public CommonResult<OfficeRespVO> getOffice(@RequestParam("id") Long id) {
        return success(officeService.getOffice(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得专业所分页")
    @PreAuthorize("@ss.hasPermission('tjt:office:query')")
    public CommonResult<PageResult<OfficeRespVO>> getOfficePage(@Valid OfficePageReqVO pageReqVO) {
        return success(officeService.getOfficePage(pageReqVO));
    }

    @GetMapping("/simple-list")
    @Operation(summary = "获得专业所精简列表")
    public CommonResult<List<OfficeSimpleRespVO>> getOfficeSimpleList() {
        return success(officeService.getOfficeSimpleList());
    }

}
