package vn.azteam.tpf.web.rest;

import com.codahale.metrics.annotation.Timed;
import io.searchbox.strings.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vn.azteam.tpf.service.TBCodeDetailsQueryService;
import vn.azteam.tpf.service.TBCodeDetailsService;
import vn.azteam.tpf.service.util.PageableUtil;
import vn.azteam.tpf.service.util.UserRoleUtil;

@RestController
@RequestMapping("/api")
public class TBCodeDetailsResource {

    private final Logger log = LoggerFactory.getLogger(TBCodeDetailsResource.class);

    private final TBCodeDetailsService tBCodeDetailsService;

    private final TBCodeDetailsQueryService tBCodeDetailsQueryService;

    private final UserRoleUtil userRoleUtil;

    private final PageableUtil pageableUtil;


    public TBCodeDetailsResource(TBCodeDetailsService tBCodeDetailsService, TBCodeDetailsQueryService tBCodeDetailsQueryService, UserRoleUtil userRoleUtil, PageableUtil pageableUtil) {
        this.tBCodeDetailsService = tBCodeDetailsService;
        this.tBCodeDetailsQueryService = tBCodeDetailsQueryService;
        this.userRoleUtil = userRoleUtil;
        this.pageableUtil = pageableUtil;
    }

    @GetMapping("/tb-codes-scan/{code}")
    @Timed
    public ResponseEntity<?> getTBCodeScan(@PathVariable String code) {
        if (StringUtils.isBlank(code)) {
            return (ResponseEntity<?>) ResponseEntity.badRequest();
        }
        tBCodeDetailsService.updateNumberScan(code);
        return ResponseEntity.ok().build();
    }
}
