package com.muyu.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.CarFence;
import com.muyu.domain.req.*;
import com.muyu.domain.resp.CarFenceGroupResp;
import com.muyu.domain.resp.CarFenceGroupsResp;
import com.muyu.domain.resp.CarFenceResp;
import com.muyu.server.service.CarFenceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 围栏数据控制层
 * @Author：yang
 * @Package：com.muyu.server.controller
 * @Project：cloud-electronic
 * @name：CarFenceController
 * @Date：2024/9/17 16:46
 */
@RequestMapping("/carFence")
@RestController
@AllArgsConstructor
@Tag(name = "查询数据",description = "从围栏信息表中查询数据")
@Log4j2
public class CarFenceController {

    private final CarFenceService carFenceService;

    /**
     * 查询围栏信息
     */
    @PostMapping("/selectConnect")
    @Operation(summary = "查询数据",description = "查询数据")
    public Result<Page<CarFenceResp>> selectConnect(
            @Validated @RequestBody CarFenceReq req
    ){
        Page<CarFenceResp> connects = carFenceService.selectCarFence(req);

        log.info("查询数据："+ connects);

        return Result.success(
                connects, "操作成功"
        );
    }

    /**
     * 电子围栏添加
     */
    @PostMapping("/addCarFence")
    @Operation(summary = "查询数据",description = "查询数据")
    public Result<String> addCarFence(
            @Validated @RequestBody CarFence carFence
    ){
        Boolean connects = carFenceService.addCarFence(carFence);

        log.info("shd");
        return connects?Result.success(
                null, "操作成功"
        ):Result.success(
                null, "操作失败"
        );
    }

    /**
     * 添加电子围栏和车辆中间表
     */
    @PostMapping("/carAddList")
    @Operation(summary = "查询数据",description = "查询数据")
    public Result<String> addCarFence(
            @Validated @RequestBody CarGroupReq req
    ){
        Boolean connects = carFenceService.addCarGroup(req);
     log.info("添加数据："+ connects);

        return connects?Result.success(
                null, "操作成功"
        ):Result.success(
                null, "操作失败"
        );
    }

    /**
     * 添加围栏和围栏组中间表
     */
    @PostMapping("/selectFenceMiddleGroup")
    @Operation(summary = "查询数据",description = "查询数据")
    public Result<String> selectFenceMiddleGroup(
            @Validated @RequestBody FenceGroupReq req
    ){
        Boolean connects = carFenceService.addFenceGroup(req);

        return connects?Result.success(
                null, "操作成功"
        ):Result.success(
                null, "操作失败"
        );
    }

    /**
     * 查询围栏和围栏组中间围栏
     */
    @PostMapping("/selectCarFenceGroupList")
    @Operation(summary = "查询数据",description = "查询数据")
    public Result<List<CarFenceGroupResp>> selectCarFenceGroupList(
            @Validated @RequestBody Integer id
    ){
        List<CarFenceGroupResp> list = carFenceService.selectCarFenceGroupList(id);
        return list.size()!=0?Result.success(
                list, "操作成功"
        ):Result.success(
                null, "未绑定围栏"
        );
    }
    /**
     * 查询中间围栏
     */
    @DeleteMapping("/carFenceGroupDel")
    @Operation(summary = "解除绑定围栏",description = "查询围栏数据")
    public Result<String> carFenceGroupDel(
            @Validated @RequestBody CarGroupIdReq carGroupIdReq
    ){
        Boolean list = carFenceService.carFenceGroupDel(carGroupIdReq);
        return list?Result.success(
                null, "操作成功"
        ):Result.success(
                null, "未绑定围栏"
        );
    }

    /**
     * 查询车辆围栏组信息
     */
    @PostMapping("/carGroupList")
    @Operation(summary = "查询车辆围栏组数据",description = "查询车辆围栏组信息")
    public Result<List<CarFenceGroupsResp>> carGroupList(@RequestBody CarFenceGroupReq req){

        List<CarFenceGroupsResp> connects = carFenceService.carGroupList(req);
        return Result.success(
                connects, "操作成功"
        );
    }
}

