// Path: website/src/main/java/fr/cph/stock/entities/ShareValue.java
// @Builder
// @AllArgsConstructor
// @NoArgsConstructor
// @Data
// public class ShareValue {
// 
// 	private Account account;
// 	private int id;
// 	private int userId;
// 	private Date date;
// 	private Double liquidityMovement;
// 	private Double yield;
// 	private Double buy;
// 	private Double sell;
// 	private Double taxe;
// 	private Double portfolioValue;
// 	private Double shareQuantity;
// 	private Double shareValue;
// 	private Double monthlyYield;
// 	private String commentary;
// 	private String details;
// 
// 	/**
// 	 * Get the jsonObject view of this class
// 	 *
// 	 * @return the jsonObject
// 	 */
// 	final JsonObject getJSONObject() {
// 		final JsonObject json = new JsonObject();
// 		json.addProperty("date", date.toString());
// 		json.addProperty(ACCOUNT, account.getName());
// 		json.addProperty("commentary", commentary);
// 		json.addProperty("shareValue", shareValue);
// 		json.addProperty("portfolioValue", portfolioValue);
// 		json.addProperty("shareQuantity", shareQuantity);
// 		json.addProperty("monthlyYield", monthlyYield);
// 		return json;
// 	}
// 
// 	/**
// 	 * Get liquidites
// 	 *
// 	 * @return the liquidites
// 	 */
// 	final Double getLiquidities() {
// 		String dets = getDetails();
// 		String updated = null;
// 		if (dets != null) {
// 			int begin = dets.indexOf("<tr><td colspan=3><b>Liquidity:</b> ");
// 			dets = dets.substring(begin);
// 			String pattern = "<tr><td colspan=3><b>Liquidity:</b> (\\-?[0-9]+\\.?[0-9]*) \\(.*";
// 			updated = dets.replaceAll(pattern, "$1");
// 		}
// 		return updated == null ? null : Double.valueOf(updated);
// 	}
// }


import fr.cph.stock.entities.ShareValue;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
 * Copyright 2017 Carl-Philipp Harmant
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fr.cph.stock.repository;



/**
 * This class implements DAO functions and add some more. It access to the ShareValue in DB.
 *
 * @author Carl-Philipp Harmant
 */
@RequiredArgsConstructor
@Component
public class ShareValueRepository implements DAO<ShareValue> {

	private static final String INSERT = "fr.cph.stock.repository.ShareValueRepository.insertOneShareValue";
	private static final String SELECT = "fr.cph.stock.repository.ShareValueRepository.selectOneShareValue";
	private static final String UPDATE = "fr.cph.stock.repository.ShareValueRepository.updateOneShareValue";
	private static final String DELETE = "fr.cph.stock.repository.ShareValueRepository.deleteOneShareValue";
	private static final String INSERT_WITH_DATE = "fr.cph.stock.repository.ShareValueRepository.insertOneShareValueWithDate";
	private static final String SELECT_LAST_VALUE = "fr.cph.stock.repository.ShareValueRepository.selectLastValue";

	@NonNull
	private final SqlSession session;

	@Override
	public final void insert(final ShareValue shareValue) {
		session.insert(INSERT, shareValue);
	}

	public final void insertWithDate(final ShareValue shareValue) {
		session.insert(INSERT_WITH_DATE, shareValue);
	}

	@Override
	public final Optional<ShareValue> select(final int id) {
		return Optional.ofNullable(session.selectOne(SELECT, id));
	}

	@Override
	public final void update(final ShareValue shareValue) {
// Path: website/src/main/java/fr/cph/stock/entities/ShareValue.java
// @Builder
// @AllArgsConstructor
// @NoArgsConstructor
// @Data
// public class ShareValue {
// 
// 	private Account account;
// 	private int id;
// 	private int userId;
// 	private Date date;
// 	private Double liquidityMovement;
// 	private Double yield;
// 	private Double buy;
// 	private Double sell;
// 	private Double taxe;
// 	private Double portfolioValue;
// 	private Double shareQuantity;
// 	private Double shareValue;
// 	private Double monthlyYield;
// 	private String commentary;
// 	private String details;
// 
// 	/**
// 	 * Get the jsonObject view of this class
// 	 *
// 	 * @return the jsonObject
// 	 */
// 	final JsonObject getJSONObject() {
// 		final JsonObject json = new JsonObject();
// 		json.addProperty("date", date.toString());
// 		json.addProperty(ACCOUNT, account.getName());
// 		json.addProperty("commentary", commentary);
// 		json.addProperty("shareValue", shareValue);
// 		json.addProperty("portfolioValue", portfolioValue);
// 		json.addProperty("shareQuantity", shareQuantity);
// 		json.addProperty("monthlyYield", monthlyYield);
// 		return json;
// 	}
// 
// 	/**
// 	 * Get liquidites
// 	 *
// 	 * @return the liquidites
// 	 */
// 	final Double getLiquidities() {
// 		String dets = getDetails();
// 		String updated = null;
// 		if (dets != null) {
// 			int begin = dets.indexOf("<tr><td colspan=3><b>Liquidity:</b> ");
// 			dets = dets.substring(begin);
// 			String pattern = "<tr><td colspan=3><b>Liquidity:</b> (\\-?[0-9]+\\.?[0-9]*) \\(.*";
// 			updated = dets.replaceAll(pattern, "$1");
// 		}
// 		return updated == null ? null : Double.valueOf(updated);
// 	}
// }


// Path: website/src/main/java/fr/cph/stock/repository/ShareValueRepository.java
import fr.cph.stock.entities.ShareValue;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;
import java.util.Optional;

/**
 * Copyright 2017 Carl-Philipp Harmant
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fr.cph.stock.repository;



/**
 * This class implements DAO functions and add some more. It access to the ShareValue in DB.
 *
 * @author Carl-Philipp Harmant
 */
@RequiredArgsConstructor
@Component
public class ShareValueRepository implements DAO<ShareValue> {

	private static final String INSERT = "fr.cph.stock.repository.ShareValueRepository.insertOneShareValue";
	private static final String SELECT = "fr.cph.stock.repository.ShareValueRepository.selectOneShareValue";
	private static final String UPDATE = "fr.cph.stock.repository.ShareValueRepository.updateOneShareValue";
	private static final String DELETE = "fr.cph.stock.repository.ShareValueRepository.deleteOneShareValue";
	private static final String INSERT_WITH_DATE = "fr.cph.stock.repository.ShareValueRepository.insertOneShareValueWithDate";
	private static final String SELECT_LAST_VALUE = "fr.cph.stock.repository.ShareValueRepository.selectLastValue";

	@NonNull
	private final SqlSession session;

	@Override
	public final void insert(final ShareValue shareValue) {
		session.insert(INSERT, shareValue);
	}

	public final void insertWithDate(final ShareValue shareValue) {
		session.insert(INSERT_WITH_DATE, shareValue);
	}

	@Override
	public final Optional<ShareValue> select(final int id) {
		return Optional.ofNullable(session.selectOne(SELECT, id));
	}

	@Override
	public final void update(final ShareValue shareValue) {
		session.update(UPDATE, shareValue);