package pwc.taxtech.atms.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.vat.entity.CellComment;
import pwc.taxtech.atms.vat.entity.PeriodCellComment;
import pwc.taxtech.atms.vat.service.impl.CellCommentServiceImpl;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping(value = "api/v1/CellComment")
public class CellCommentController {
    @Autowired
    CellCommentServiceImpl cellCommentService;

    @RequestMapping(value = "List", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public OperationResultDto<List<PeriodCellComment>> getCellComments(@RequestParam("cellDataId") Optional<Long> cellDataId, @RequestHeader("from") String form) {
        String projectId = StringUtils.EMPTY;
        if (StringUtils.isNotBlank(form) && form.split("@").length > 0) {
            projectId = form.split("@")[0];
        }
        return cellCommentService.getCellComments(cellDataId, projectId);
    }
}