package org.dromara.system.controller.room;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.PositionList;
import org.dromara.system.domain.bo.PositionBoStr;
import org.dromara.system.domain.vo.PositionDetailVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.PositionVo;
import org.dromara.system.domain.bo.PositionBo;
import org.dromara.system.service.IPositionService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 【请填写功能名称】
 *
 * @author Lion Li
 * @date 2025-03-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/position")
public class PositionController extends BaseController {

    private final IPositionService positionService;

    /**
     * 查询定位列表
     */
    @SaCheckPermission("system:position:list")
    @GetMapping("/list")
    public TableDataInfo<PositionVo> list(PositionBo bo, PageQuery pageQuery) {
        return positionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出定位列表
     */
    @SaCheckPermission("system:position:export")
    @Log(title = "导出定位列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PositionBo bo, HttpServletResponse response) {
        List<PositionVo> list = positionService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", PositionVo.class, response);
    }

    /**
     * 获取定位详细信息
     *
     * @param positionId 主键
     */
    @SaCheckPermission("system:position:query")
    @GetMapping("/{positionId}")
    public R<PositionVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String positionId) {
        return R.ok(positionService.queryById(positionId));
    }

    /**
     * 新增定位
     */
    @SaCheckPermission("system:position:add")
    @Log(title = "新增定位信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PositionBoStr bo) {
        return toAjax(positionService.insertByBo(bo));
    }

    /**
     * 修改定位
     */
    @SaCheckPermission("system:position:edit")
    @Log(title = "修改定位信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PositionBoStr bo) {
        return toAjax(positionService.updateByBo(bo));
    }

    /**
     * 删除定位
     *
     * @param positionIds 主键串
     */
    @SaCheckPermission("system:position:remove")
    @Log(title = "删除定位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{positionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] positionIds) {
        return toAjax(positionService.deleteWithValidByIds(List.of(positionIds), true));
    }

    /**
     * 获取定位列表
     * @return
     */
    @GetMapping("/group")
    public R<List<PositionVo>> index() {
        List<PositionVo> list =positionService.selectAll();
        return R.ok(list);
    }

    /**
     * 获取定位下社区里的房型列表
     * @param positionId
     * @return
     */
    @GetMapping("/room/{positionId}")
    public R<PositionVo> roomList(@PathVariable String positionId) {
        PositionVo vo =positionService.selectByPositionId(positionId);
        return R.ok(vo);
    }

    /**
     * 获取定位下社区里房型区域详情
     * @param positionId
     * @param communityId
     * @param roomId
     * @return
     */
    @GetMapping("/room/detail/{positionId}/{communityId}/{roomId}")
    public R<PositionDetailVo> roomDetail(@PathVariable String positionId,@PathVariable String communityId,@PathVariable String roomId) {
        PositionDetailVo vo = positionService.selectByRoomDetail(positionId, communityId, roomId);
        return R.ok(vo);
    }

    @GetMapping("/ficationBtn")
    public R<List<PositionList>> classBtn() {
        List<PositionList> list = positionService.ficationBtn();
        return R.ok(list);
    }
}
