package com.yc.ship.module.resource.controller.admin.shiptype;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.yc.ship.framework.common.pojo.PageParam;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.pojo.CommonResult;
import com.yc.ship.framework.common.util.object.BeanUtils;
import static com.yc.ship.framework.common.pojo.CommonResult.success;

import com.yc.ship.framework.excel.core.util.ExcelUtils;

import com.yc.ship.framework.apilog.core.annotation.ApiAccessLog;
import static com.yc.ship.framework.apilog.core.enums.OperateTypeEnum.*;

import com.yc.ship.module.resource.controller.admin.shiptype.vo.*;
import com.yc.ship.module.resource.dal.dataobject.shiptype.ResourceShipTypeDO;
import com.yc.ship.module.resource.service.shiptype.ResourceShipTypeService;

@Tag(name = "管理后台 - 资源管理-游轮类型管理")
@RestController
@RequestMapping("/resource/ship-type")
@Validated
public class ResourceShipTypeController {

    @Resource
    private ResourceShipTypeService shipTypeService;

    @PostMapping("/create")
    @Operation(summary = "创建资源管理-游轮类型管理")
    @PreAuthorize("@ss.hasPermission('resource:ship-type:create')")
    public CommonResult<Long> createShipType(@Valid @RequestBody ResourceShipTypeSaveReqVO createReqVO) {
        return success(shipTypeService.createShipType(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新资源管理-游轮类型管理")
    @PreAuthorize("@ss.hasPermission('resource:ship-type:update')")
    public CommonResult<Boolean> updateShipType(@Valid @RequestBody ResourceShipTypeSaveReqVO updateReqVO) {
        shipTypeService.updateShipType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除资源管理-游轮类型管理")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('resource:ship-type:delete')")
    public CommonResult<Boolean> deleteShipType(@RequestParam("id") Long id) {
        shipTypeService.deleteShipType(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得资源管理-游轮类型管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('resource:ship-type:query')")
    public CommonResult<ResourceShipTypeRespVO> getShipType(@RequestParam("id") Long id) {
        ResourceShipTypeDO shipType = shipTypeService.getShipType(id);
        return success(BeanUtils.toBean(shipType, ResourceShipTypeRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得资源管理-游轮类型管理分页")
    @PreAuthorize("@ss.hasPermission('resource:ship-type:query')")
    public CommonResult<PageResult<ResourceShipTypeRespVO>> getShipTypePage(@Valid ResourceShipTypePageReqVO pageReqVO) {
        PageResult<ResourceShipTypeDO> pageResult = shipTypeService.getShipTypePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResourceShipTypeRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出资源管理-游轮类型管理 Excel")
    @PreAuthorize("@ss.hasPermission('resource:ship-type:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportShipTypeExcel(@Valid ResourceShipTypePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResourceShipTypeDO> list = shipTypeService.getShipTypePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "资源管理-游轮类型管理.xls", "数据", ResourceShipTypeRespVO.class,
                        BeanUtils.toBean(list, ResourceShipTypeRespVO.class));
    }

    @GetMapping("/list-simple")
    @Operation(summary = "获得资源管理-游轮类型管理列表")
    public CommonResult<List<ResourceShipTypeRespVO>> getShipTypeListSimple() {
        List<ResourceShipTypeDO> list = shipTypeService.getListSimple();
        return success(BeanUtils.toBean(list, ResourceShipTypeRespVO.class));
    }

}