class AssuranceServiceImpl implements AssuranceService {

    @Override
    public Response create(int typeIndex, String orderId, HttpHeaders headers) {
        Assurance a = assuranceRepository.findByOrderId(UUID.fromString(orderId));
        AssuranceType at = AssuranceType.getTypeByIndex(typeIndex);
        if (a != null) {
            AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][AddAssurance] Fail.Assurance already exists");
            return new Response<>(0, "Fail.Assurance already exists", null);
        } else if (at == null) {
            AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][AddAssurance] Fail.Assurance type doesn't exist");
            return new Response<>(0, "Fail.Assurance type doesn't exist", null);
        } else {
            Assurance assurance = new Assurance(UUID.randomUUID(), UUID.fromString(orderId), at);
            assuranceRepository.save(assurance);
            AssuranceServiceImpl.LOGGER.info("[Assurance-Add&Delete-Service][AddAssurance] Success.");
            return new Response<>(1, "Success", assurance);
        }
    }

}