package ru.micord.ervu.account_applications.dao;

import java.util.List;
import java.util.UUID;

import org.jooq.DSLContext;
import org.jooq.Record2;
import org.jooq.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import ru.micord.ervu.account_applications.db_beans.public_.tables.records.RecruitmentRecord;
import ru.micord.ervu.account_applications.db_beans.public_.tables.records.UserApplicationRoleRecord;

import static ru.micord.ervu.account_applications.db_beans.public_.tables.Recruitment.RECRUITMENT;
import static ru.micord.ervu.account_applications.db_beans.public_.tables.UserApplicationRole.USER_APPLICATION_ROLE;

/**
 * @author Eduard Tihomirov
 */
@Repository
public class ErvuDirectoriesDao {

  @Autowired
  private DSLContext dsl;

  public List<String> getRoleIds() {
    return dsl.select(USER_APPLICATION_ROLE.USER_ROLE_ID)
        .from(USER_APPLICATION_ROLE)
        .fetch(USER_APPLICATION_ROLE.USER_ROLE_ID);
  }

  public Result<Record2<UUID, String>> getDomainIds() {
    return dsl.select(RECRUITMENT.ID, RECRUITMENT.IDM_ID)
        .from(RECRUITMENT)
        .fetch();
  }

  public UserApplicationRoleRecord getRoleRecord() {
    return dsl.newRecord(USER_APPLICATION_ROLE);
  }

  public RecruitmentRecord getRecruitmentRecord() {
    return dsl.newRecord(RECRUITMENT);
  }

  public void insertRecruitmentRecords(List<RecruitmentRecord> newRecruitmentRecords) {
    dsl.batchInsert(newRecruitmentRecords).execute();
  }

  public void updateRecruitmentRecords(List<RecruitmentRecord> recruitmentRecords) {
    dsl.batchUpdate(recruitmentRecords).execute();
  }

  public void insertRoleRecords(List<UserApplicationRoleRecord> newRoleRecords) {
    dsl.batchInsert(newRoleRecords).execute();
  }

  public void updateRoleRecords(List<UserApplicationRoleRecord> roleRecords ) {
    dsl.batchUpdate(roleRecords).execute();
  }
}
