package ovh.herisson.Clyde.EndPoints;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Services.*;
import ovh.herisson.Clyde.Tables.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")

public class MockController {
    private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    public final UserRepository userRepo;
    public final TokenRepository tokenRepo;
    public final TokenService tokenService;
    public final CurriculumCourseService CurriculumCourseService;
    public final CurriculumService curriculumService;
    public final CourseService courseService;

    public final InscriptionService inscriptionService;
    ArrayList<User> mockUsers;


    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService){
        this.tokenRepo = tokenRepo;
        this.userRepo = userRepo;
        this.tokenService = tokenService;
        this.CurriculumCourseService = CurriculumCourseService;
        this.curriculumService = curriculumService;
        this.courseService = courseService;
        this.inscriptionService = inscriptionService;
    }

    /** Saves an example of each user type by :
     * email : FooRole@FooRole.com, password : FooRole and token : FooRole
     * For example the admin as "admin@admin.com" as email and "admin" as both password and token
     * They all have silly names
     */

    @PostMapping("/mock")
    public void postMock(){

        // user part


        User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
        User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
        User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary"));
        User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
        User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.InscriptionService,passwordEncoder.encode("inscriptionService"));
        mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena));

        userRepo.saveAll(mockUsers);

        // Course / Curriculum part

        Curriculum infoBab1 = new Curriculum(1,"info");
        Curriculum chemistryBab1 = new Curriculum(1,"chemistry");
        Curriculum psychologyBab1 = new Curriculum(1,"psychology");

        curriculumService.save(infoBab1);
        curriculumService.save(chemistryBab1);
        curriculumService.save(psychologyBab1);


        Course progra1 = new Course(5,"Programmation et algorithmique 1",joke);
        Course chemistry1 = new Course(12, "Thermochimie",joke);
        Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho",joke);
        Course commun = new Course(2, "cours commun",joke);

        courseService.save(progra1);
        courseService.save(chemistry1);
        courseService.save(psycho1);
        courseService.save(commun);


        CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1));
        CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));

        CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1));
        CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));


        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,commun));
        CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));


        InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Refused,"yes.png","password");

        inscriptionService.save(inscriptionRequest);
        
    }
}

