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.ParkingSpaceDto;
import com.sptg.estate.api.entity.ParkingSpace;
import com.sptg.estate.api.feigns.ParkingSpaceFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/estate/parkingSpace")
@RequiredArgsConstructor
public class ParkingSpaceController {
    private final ParkingSpaceFeign ParkingSpaceFeign;

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

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

    @GetMapping(value = "/editView/{id}")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGSPACE_EDIT,format = DataFormatEnum.VIEW)
    public ModelAndView editView(@PathVariable Long id){
        ParkingSpace parkingSpace = this.ParkingSpaceFeign.getById(id);
        ModelAndView modelAndView = new ModelAndView("estate/parking-space-edit");
        modelAndView.addObject("parkingSpace",parkingSpace);
        return modelAndView;
    }

    @GetMapping(value = "/page")
    @Security(token = EstateSecurityToken.ESTATE_PARKINGSPACE_MANAGE,format = DataFormatEnum.JSON)
    public ResultBean<Page<ParkingSpace>> page(ParkingSpaceDto dto,Page<ParkingSpace> page){
        dto.setPage(page);
        return this.ParkingSpaceFeign.page(dto);
    }

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

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

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