from infrahub.core.constants import (
    BranchSupportType,
    InfrahubKind,
    RelationshipDeleteBehavior,
)
from infrahub.proposed_change.constants import ProposedChangeState

core_proposed_change = {
    "name": "ProposedChange",
    "namespace": "Core",
    "description": "Metadata related to a proposed change",
    "include_in_menu": False,
    "icon": "mdi:file-replace-outline",
    "label": "Proposed Change",
    "default_filter": "name__value",
    "display_labels": ["name__value"],
    "generate_profile": False,
    "branch": BranchSupportType.AGNOSTIC.value,
    "inherit_from": [InfrahubKind.TASKTARGET],
    "documentation": "/topics/proposed-change",
    "attributes": [
        {"name": "name", "kind": "Text", "optional": False},
        {"name": "description", "kind": "TextArea", "optional": True},
        {"name": "source_branch", "kind": "Text", "optional": False},
        {"name": "destination_branch", "kind": "Text", "optional": False},
        {
            "name": "state",
            "kind": "Text",
            "enum": ProposedChangeState.available_types(),
            "default_value": ProposedChangeState.OPEN.value,
            "optional": True,
        },
    ],
    "relationships": [
        {
            "name": "approved_by",
            "peer": InfrahubKind.GENERICACCOUNT,
            "optional": True,
            "cardinality": "many",
            "kind": "Attribute",
            "branch": BranchSupportType.AGNOSTIC.value,
            "identifier": "coreaccount__proposedchange_approved_by",
        },
        {
            "name": "reviewers",
            "peer": InfrahubKind.GENERICACCOUNT,
            "optional": True,
            "kind": "Attribute",
            "cardinality": "many",
            "branch": BranchSupportType.AGNOSTIC.value,
            "identifier": "coreaccount__proposedchange_reviewed_by",
        },
        {
            "name": "created_by",
            "peer": InfrahubKind.GENERICACCOUNT,
            "optional": True,
            "cardinality": "one",
            "branch": BranchSupportType.AGNOSTIC.value,
            "identifier": "coreaccount__proposedchange_created_by",
        },
        {
            "name": "comments",
            "peer": InfrahubKind.CHANGECOMMENT,
            "kind": "Component",
            "optional": True,
            "cardinality": "many",
            "on_delete": RelationshipDeleteBehavior.CASCADE,
        },
        {
            "name": "threads",
            "peer": InfrahubKind.THREAD,
            "identifier": "proposedchange__thread",
            "kind": "Component",
            "optional": True,
            "cardinality": "many",
            "on_delete": RelationshipDeleteBehavior.CASCADE,
        },
        {
            "name": "validations",
            "peer": InfrahubKind.VALIDATOR,
            "kind": "Component",
            "identifier": "proposed_change__validator",
            "optional": True,
            "cardinality": "many",
            "on_delete": RelationshipDeleteBehavior.CASCADE,
        },
    ],
}
