package com.bytesw.bytebot.controller;

import com.bytesw.bytebot.bean.CalendarExceptionBean;
import com.bytesw.bytebot.service.CalendarExceptionService;
import com.bytesw.xdf.annotation.ProgramSecurity;
import com.bytesw.xdf.controller.XDFController;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;

import java.util.List;
import java.util.Map;

@RestController()
@RequestMapping("/service/settings/calendar-exception")
@ProgramSecurity("CALENDAR-EXCEPTION")
@Log4j2
public class CalendarExceptionController extends XDFController<CalendarExceptionBean, BigInteger> {

    @Autowired
    CalendarExceptionService service;

    public CalendarExceptionController(CalendarExceptionService service) {
        super(service);
    }

    @ApiResponses({@ApiResponse(
            code = 200,
            message = "Success",
            response = ResponseEntity.class
    ), @ApiResponse(
            code = 404,
            message = "Not Found"
    ), @ApiResponse(
            code = 505,
            message = "Internal Server Error"
    )})
    @RequestMapping(
            value = {"/find-by-calendar-id"},
            method = {RequestMethod.POST}
    )
    @ResponseBody
    @PreAuthorize("hasPermission(this, 'view')")
    public ResponseEntity<String> getCalendarExceptionbyID(@RequestBody Map<String, String> parametersCalendar, HttpServletRequest req) {

        List<CalendarExceptionBean> calendarExceptionBeanList = this.service.getCalendarExceptionbyID(parametersCalendar);

        return new ResponseEntity(this.gson.toJson(calendarExceptionBeanList), HttpStatus.OK);
    }
}
