package com.iqser.red.service.persistence.service.v1.api.external.resource;

import java.time.OffsetDateTime;
import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.iqser.red.service.persistence.service.v1.api.shared.model.NotificationResponse;
import com.iqser.red.service.persistence.service.v1.api.shared.model.common.JSONPrimitive;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;

public interface NotificationResource {

    String NOTIFICATION_PATH = ExternalApi.BASE_PATH + "/notification";
    String TOGGLE_SEEN_PATH = "/toggle-seen";
    String TOGGLE_READ_PATH = "/toggle-read";
    String DELETE_PATH = "/delete";
    String CHANGES_SINCE_PATH = "/changes";

    String INCLUDE_SEEN_PARAM = "includeSeen";
    String SET_SEEN_PARAM = "setSeen";
    String SET_READ_PARAM = "setRead";


    @ResponseBody
    @PostMapping(value = NOTIFICATION_PATH + CHANGES_SINCE_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "See if there are new notifications since param", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Success."), @ApiResponse(responseCode = "404", description = "Dossier does not exist.")})
    JSONPrimitive<Boolean> hasNewNotificationsSince(@RequestBody JSONPrimitive<OffsetDateTime> since);


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @Operation(summary = "Mark a notifications as seen or unseen", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK")})
    @PostMapping(value = NOTIFICATION_PATH + TOGGLE_SEEN_PATH, consumes = MediaType.APPLICATION_JSON_VALUE)
    void toggleNotificationSeen(@RequestBody List<String> notificationIds, @RequestParam(SET_SEEN_PARAM) boolean setSeen);


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @Operation(summary = "Mark a notifications as read or unread", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK")})
    @PostMapping(value = NOTIFICATION_PATH + TOGGLE_READ_PATH, consumes = MediaType.APPLICATION_JSON_VALUE)
    void toggleNotificationRead(@RequestBody List<String> notificationIds, @RequestParam(SET_READ_PARAM) boolean setRead);


    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @Operation(summary = "Delete notifications", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "OK")})
    @PostMapping(value = NOTIFICATION_PATH + DELETE_PATH, consumes = MediaType.APPLICATION_JSON_VALUE)
    void delete(@RequestBody List<String> notificationIds);


    @ResponseBody
    @ResponseStatus(value = HttpStatus.OK)
    @Operation(summary = "Retrieves notifications for the current user", description = "None")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
    @GetMapping(value = NOTIFICATION_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
    NotificationResponse getNotifications(@RequestParam(INCLUDE_SEEN_PARAM) boolean includeSeen);

}
