package bg.car_wash.configurations.database;

import bg.car_wash.areas.user.entity.User;
import bg.car_wash.areas.user.entity.UserType;
import bg.car_wash.configurations.user.UserConfiguration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

public class InsertUsers {

	private BCryptPasswordEncoder bCryptPasswordEncoder;

	private String password;

	private List<User> users;

	public InsertUsers() {
		this.users = new LinkedList<>();
		this.bCryptPasswordEncoder = new BCryptPasswordEncoder();
		this.password = this.bCryptPasswordEncoder.encode("123456");
		this.initUsers();
	}

	public void initUsers() {
		User u1 = new User();
		u1.setEmail("ivaylo.ivanof@gmail.com");
		u1.setFullName("Ivaylo Ivanov");
		u1.setPassword(this.password);
		u1.setUserType(UserType.ADMIN);
		u1.setRemuneration(new BigDecimal(UserConfiguration.ADMIN_REMUNERATION));
		u1.setAccountNonExpired(true);
		u1.setAccountNonLocked(true);
		u1.setCredentialsNonExpired(true);
		u1.setEnabled(true);

		User u2 = new User();
		u2.setEmail("pesho@abv.bg");
		u2.setFullName("Pesho Peshev");
		u2.setPassword(this.password);
		u2.setUserType(UserType.DIRECTOR);
		u2.setRemuneration(new BigDecimal(UserConfiguration.DIRECTOR_REMUNERATION));
		u2.setAccountNonExpired(true);
		u2.setAccountNonLocked(true);
		u2.setCredentialsNonExpired(true);
		u2.setEnabled(true);

		User u3 = new User();
		u3.setEmail("asen@abv.bg");
		u3.setFullName("Asen Asenov");
		u3.setPassword(this.password);
		u3.setUserType(UserType.WORKER);
		u3.setRemuneration(new BigDecimal(UserConfiguration.WORKER_REMUNERATION));
		u3.setAccountNonExpired(true);
		u3.setAccountNonLocked(true);
		u3.setCredentialsNonExpired(true);
		u3.setEnabled(true);

		User u4 = new User();
		u4.setEmail("krum@abv.bg");
		u4.setFullName("Krum Krumov");
		u4.setPassword(this.password);
		u4.setUserType(UserType.PAYMASTER);
		u4.setRemuneration(new BigDecimal(UserConfiguration.PAYMASTER_REMUNERATION));
		u4.setAccountNonExpired(true);
		u4.setAccountNonLocked(true);
		u4.setCredentialsNonExpired(true);
		u4.setEnabled(true);

		this.users.add(u1);
		this.users.add(u2);
		this.users.add(u3);
		this.users.add(u4);
	}

	public List<User> getUsers() {
		return this.users;
	}
}

@@ -760,28 +760,18 @@
 %22iva
-ylo.ivanof@gmail.com
+nof@abv.bg
 %22);%0A
@@ -951,133 +951,8 @@
 N));
-%0A%09%09u1.setAccountNonExpired(true);%0A%09%09u1.setAccountNonLocked(true);%0A%09%09u1.setCredentialsNonExpired(true);%0A%09%09u1.setEnabled(true);
 %0A%0A%09%09
@@ -1028,17 +1028,17 @@
 (%22Pe
-sho Peshe
+tar Petro
 v%22);
@@ -1190,133 +1190,8 @@
 N));
-%0A%09%09u2.setAccountNonExpired(true);%0A%09%09u2.setAccountNonLocked(true);%0A%09%09u2.setCredentialsNonExpired(true);%0A%09%09u2.setEnabled(true);
 %0A%0A%09%09
@@ -1423,133 +1423,8 @@
 N));
-%0A%09%09u3.setAccountNonExpired(true);%0A%09%09u3.setAccountNonLocked(true);%0A%09%09u3.setCredentialsNonExpired(true);%0A%09%09u3.setEnabled(true);
 %0A%0A%09%09
@@ -1663,130 +1663,476 @@
 ));%0A
+%0A
 %09%09
-u4.setAccountNonExpired(true
+User u5 = new User();%0A%09%09u5.setEmail(%22asen@abv.bg%22);%0A%09%09u5.setFullName(%22Asen Asenov%22);%0A%09%09u5.setPassword(this.password);%0A%09%09u5.setUserType(UserType.WORKER
 );%0A%09%09u
-4
+5
 .set
-AccountNonLocked(true
+Remuneration(new BigDecimal(UserConfiguration.WASHER_REMUNERATION));%0A%0A%09%09User u6 = new User(
 );%0A%09%09u
-4
+6
 .set
-CredentialsNonExpired(true
+Email(%22pavel@abv.bg%22);%0A%09%09u6.setFullName(%22Pavel Pavlov%22);%0A%09%09u6.setPassword(this.password);%0A%09%09u6.setUserType(UserType.WORKER
 );%0A%09%09u
-4
+6
 .set
-Enabled(true
+Remuneration(new BigDecimal(UserConfiguration.LAUNDERER_REMUNERATION)
 );%0A%0A
@@ -2219,16 +2219,240 @@
 dd(u4);%0A
+%09%09this.users.add(u5);%0A%09%09this.users.add(u6);%0A%0A%09%09for (User user : this.getUsers()) %7B%0A%09%09%09user.setAccountNonExpired(true);%0A%09%09%09user.setAccountNonLocked(true);%0A%09%09%09user.setCredentialsNonExpired(true);%0A%09%09%09user.setEnabled(true);%0A%09%09%7D%0A
 %09%7D%0A%0A%09pub

update insert default users