# ============================================================
# ARTIFACT MANAGEMENT TRIGGERS
# ============================================================

# Artifact Ownership & Quality
qyv_ai_has_equippable_artifacts = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_artifact = {
            is_equippable = yes
            owner = root
            NOT = { equipped_by = root }
        }
    }
}

qyv_ai_has_unequipped_quality_artifacts = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_artifact = {
            is_equippable = yes
            owner = root
            NOT = { equipped_by = root }
            quality >= 2
        }
    }
}

qyv_ai_has_equipped_suboptimal = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_equipped_artifact = {
            quality < 3
            any_artifact = {
                is_equippable = yes
                owner = root
                quality > equipped_artifact.quality
                slot = equipped_artifact.slot
            }
        }
    }
}

# Artifact Acquisition
qyv_ai_should_hunt_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        gold >= 1000
        NOT = { in_debt = yes }
        NOT = { has_character_flag = artifact_hunt_cooldown }
        any_artifact = {
            is_equippable = yes
            NOT = { owner = root }
            quality >= 3
            owner = {
                is_ruler = yes
                NOT = { is_allied_to = root }
                military_strength < root.military_strength * 1.5
            }
        }
    }
}

qyv_ai_should_forge_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        gold >= 500
        NOT = { in_debt = yes }
        any_courtier = {
            is_artificer = yes
            skill >= 10
        }
    }
}

qyv_ai_should_steal_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        intrigue >= 14
        any_artifact = {
            is_equippable = yes
            NOT = { owner = root }
            quality >= 3
            owner = {
                is_ruler = yes
                NOT = { is_allied_to = root }
                NOT = { has_truce_with = root }
            }
        }
    }
}

qyv_ai_should_gift_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_artifact = {
            is_equippable = yes
            owner = root
            NOT = { equipped_by = root }
            quality >= 2
        }
        any_neighbor_independent_ruler = {
            limit = {
                NOT = { is_allied_to = root }
                opinion_of_self < 0
                military_strength > root.military_strength * 1.2
            }
            save_scope_as = gift_target
        }
    }
}

qyv_ai_should_equip_best = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_equipped_artifact = {
            any_artifact = {
                is_equippable = yes
                owner = root
                slot = equipped_artifact.slot
                quality > equipped_artifact.quality
            }
        }
    }
}

qyv_ai_should_equip_heir = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_child = {
            is_heir = yes
            is_adult = yes
            any_artifact = {
                is_equippable = yes
                owner = root
                NOT = { equipped_by = root }
                slot = any_equipped_artifact.slot
                quality > any_equipped_artifact.quality
            }
        }
    }
}

# Artifact Claiming
qyv_ai_should_claim_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_artifact = {
            is_equippable = yes
            quality >= 3
            has_claimant = root
            owner = {
                is_ruler = yes
                NOT = { is_allied_to = root }
            }
        }
    }
}

# Artifact Forging Quality
qyv_ai_should_forge_specific = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        gold >= 1000
        NOT = { in_debt = yes }
        any_artifact_slot = {
            NOT = { has_equipped_artifact = root }
            OR = {
                any_equipped_artifact = { quality < 3 }
            }
        }
    }
}

# Artifact for Heir/Knight
qyv_ai_should_equip_knight = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        any_knight = {
            prowess >= 15
            any_artifact = {
                is_equippable = yes
                owner = root
                NOT = { equipped_by = root }
                slot = weapon
                quality >= 2
            }
        }
    }
}

# Artifact for Duel
qyv_ai_should_prepare_duel_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        is_challenged = yes
        any_artifact = {
            is_equippable = yes
            owner = root
            quality >= 3
            slot = weapon
        }
    }
}

# Artifact Ransom
qyv_ai_should_ransom_artifact = {
    trigger = {
        is_ai = yes
        is_ruler = yes
        gold < 500
        any_artifact = {
            is_equippable = yes
            owner = root
            NOT = { equipped_by = root }
            quality <= 2
        }
    }
}

# Artifact Cooldown
qyv_ai_artifact_hunt_cooldown = {
    trigger = {
        has_character_flag = artifact_hunt_cooldown
    }
}