package com.sptg.gateway.controller.estate;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.estate.api.constant.EstateSecurityToken;
import com.sptg.estate.api.dto.ParkingLotDto;
import com.sptg.estate.api.entity.ParkingLot;
import com.sptg.estate.api.feigns.ParkingLotFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/estate/parkingLot")
@RequiredArgsConstructor
public class ParkingLotController {
    private final ParkingLotFeign ParkingLotFeign;

    @GetMapping(value = "/index")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_MANAGE,format = DataFormatEnum.VIEW)
    public ModelAndView index(){
        return new ModelAndView("estate/parking-lot-manage");
    }

    @GetMapping(value = "/addView")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_ADD,format = DataFormatEnum.VIEW)
    public ModelAndView addVieW(ParkingLotDto dto){
        ModelAndView modelAndView = new ModelAndView("estate/parking-lot-add");
        return modelAndView;
    }

    @GetMapping(value = "/editView/{id}")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_EDIT,format = DataFormatEnum.VIEW)
    public ModelAndView editView(@PathVariable Long id){
        ParkingLot parkingLot = this.ParkingLotFeign.getById(id);
        ModelAndView modelAndView = new ModelAndView("estate/parking-lot-edit");
        modelAndView.addObject("parkingLot",parkingLot);
        return modelAndView;
    }

    @GetMapping(value = "/page")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_MANAGE,format = DataFormatEnum.JSON)
    public ResultBean<Page<ParkingLot>> page(ParkingLotDto dto,Page<ParkingLot> page){
        dto.setPage(page);
        return this.ParkingLotFeign.page(dto);
    }

    @PostMapping(value = "/add")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_ADD,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> add(ParkingLotDto dto){
        return this.ParkingLotFeign.add(dto);
    }

    @PostMapping(value = "/edit")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_EDIT,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> edit(ParkingLotDto dto){
        return this.ParkingLotFeign.edit(dto);
    }

    @PostMapping(value = "/delete")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGLOT_DELETE,format = DataFormatEnum.JSON)
    public ResultBean<Boolean> delete(ParkingLotDto dto){
        return this.ParkingLotFeign.delete(dto);
    }
}
