use super::super::super::blockers::territory_target_import_blocker;
use super::super::condition_targets::chairman_target_import_blocker;
use super::super::import_outcome::{
    company_target_allowed_for_import, company_target_import_error_message,
    player_target_allowed_for_import, player_target_import_error_message,
};
use crate::documents::RuntimeImportContext;
use crate::event::targets::{
    RuntimeChairmanTarget, RuntimeCompanyTarget, RuntimePlayerTarget, RuntimeTerritoryTarget,
};

pub(super) fn import_company_target(
    target: &RuntimeCompanyTarget,
    runtime_context: &RuntimeImportContext,
    allow_condition_true_company: bool,
) -> Result<RuntimeCompanyTarget, String> {
    if company_target_allowed_for_import(target, runtime_context, allow_condition_true_company) {
        Ok(target.clone())
    } else {
        Err(company_target_import_error_message(target, runtime_context))
    }
}

pub(super) fn import_player_target(
    target: &RuntimePlayerTarget,
    runtime_context: &RuntimeImportContext,
    allow_condition_true_player: bool,
) -> Result<RuntimePlayerTarget, String> {
    if player_target_allowed_for_import(target, runtime_context, allow_condition_true_player) {
        Ok(target.clone())
    } else {
        Err(player_target_import_error_message(target, runtime_context))
    }
}

pub(super) fn import_territory_target(
    target: &RuntimeTerritoryTarget,
    runtime_context: &RuntimeImportContext,
) -> Result<RuntimeTerritoryTarget, String> {
    if territory_target_import_blocker(target, runtime_context).is_none() {
        Ok(target.clone())
    } else {
        Err("packed effect requires territory runtime context".to_string())
    }
}

pub(super) fn import_chairman_target(
    target: &RuntimeChairmanTarget,
    runtime_context: &RuntimeImportContext,
) -> Result<RuntimeChairmanTarget, String> {
    if chairman_target_import_blocker(target, runtime_context).is_none() {
        Ok(target.clone())
    } else {
        Err("packed effect requires chairman runtime context".to_string())
    }
}
