package ru.micord.ervu.account_applications.dao;

import java.util.List;
import java.util.Map;

import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Table;
import org.springframework.stereotype.Repository;
import ru.micord.ervu.account_applications.db_beans.public_.Tables;
import ru.micord.ervu.account_applications.db_beans.public_.tables.records.RecruitmentSolutionRecord;

/**
 * @author Adel Kalimullin
 */
@Repository
public class RecruitmentSolutionDao extends AbstractDataDao<RecruitmentSolutionRecord> {
  protected RecruitmentSolutionDao(DSLContext dsl) {
    super(dsl);
  }

  public List<String> getSolutionIdsByRecruitmentId(String recruitmentId) {
    return getValuesByField(
        Tables.RECRUITMENT_SOLUTION.SOLUTION_ID,
        Tables.RECRUITMENT_SOLUTION.RECRUITMENT_ID, recruitmentId
    );
  }

  public void deleteRecruitmentSolutionsByRecruitmentIdAndSolutionIds(String recruitmentId,
      List<String> solutionIds) {
    deleteByFieldAndInValues(
        Tables.RECRUITMENT_SOLUTION.RECRUITMENT_ID, recruitmentId,
        Tables.RECRUITMENT_SOLUTION.SOLUTION_ID, solutionIds
    );
  }


  public void deleteRecruitmentSolution(RecruitmentSolutionRecord record) {
    Map<Field<String>, String> conditions = Map.of(
        Tables.RECRUITMENT_SOLUTION.RECRUITMENT_ID, record.getRecruitmentId(),
        Tables.RECRUITMENT_SOLUTION.SOLUTION_ID, record.getSolutionId()
    );

    deleteByValues(conditions);
  }

  @Override
  protected Table<RecruitmentSolutionRecord> getTable() {
    return Tables.RECRUITMENT_SOLUTION;
  }
}
