# Copyright (c) 2024 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com

from enum import StrEnum

from pydantic import BaseModel, Field

from czpulumi.sumo_logic.models import ConfiguredBaseModel

CLOUDTRAIL_ROLE_ARN = 'arn:aws:iam::893909132307:role/CZ-SumoLogic-CloudTrail-Access-Role-SumoRole-6HktExmvMU4X'


class CloudProvider(StrEnum):
    AWS = 'aws'
    GCP = 'gcp'
    AZURE = 'azure'


class AwsRegion(StrEnum):
    US_EAST_1 = 'us-east-1'


def get_short_region(region: str) -> str:
    return region.replace('-', '')[:3] + region.split('-')[-1]


class AccountEnvironment(StrEnum):
    SANDBOX = 'sandbox'
    DEV = 'dev'
    PROD = 'prod'
    SHARED = 'shared'


class AwsRoleArns(BaseModel):
    sumo_logic_role_arn: str = Field('', description='Sumo Logic Role ARN')
    cloudtrail_role_arn: str = Field('', description='CloudTrail Role ARN')


class CloudAccount(ConfiguredBaseModel):
    account_id: str = Field(..., description='Account ID')
    name: str = Field(..., description='Account name')
    provider: CloudProvider = Field(..., description='Cloud Provider')
    supported_regions: list[AwsRegion] = Field([], description='Supported regions for the account')
    environment: AccountEnvironment = Field(..., description='Type of environment the account hosts')
    aws_role_arns: AwsRoleArns = Field(..., description='Role ARNs for the account. Managed by Cloudzero/ops-cloud')


CZ_CLOUD_ACCOUNTS = {
    'dev-core': CloudAccount(
        name='dev-core',
        account_id='618300337335',
        provider=CloudProvider.AWS,
        supported_regions=[AwsRegion.US_EAST_1],
        environment=AccountEnvironment.DEV,
        aws_role_arns=AwsRoleArns(
            sumo_logic_role_arn='arn:aws:iam::618300337335:role/sumo-logic-role-SumoRole-HgGS3p5TjYYJ',
        ),
    ),
    'dev-reactor': CloudAccount(
        name='dev-reactor',
        account_id='998146006915',
        provider=CloudProvider.AWS,
        supported_regions=[AwsRegion.US_EAST_1],
        environment=AccountEnvironment.DEV,
        aws_role_arns=AwsRoleArns(
            sumo_logic_role_arn='arn:aws:iam::998146006915:role/sumo-logic-role-SumoRole-VlaiJ3BeoiBv',
        ),
    ),
    'prod-core': CloudAccount(
        name='prod-core',
        account_id='931830253929',
        provider=CloudProvider.AWS,
        supported_regions=[AwsRegion.US_EAST_1],
        environment=AccountEnvironment.PROD,
        aws_role_arns=AwsRoleArns(
            sumo_logic_role_arn='arn:aws:iam::931830253929:role/sumo-logic-role-SumoRole-CZrfkH9vQipy',
        ),
    ),
    'prod-reactor': CloudAccount(
        name='prod-reactor',
        account_id='061190967865',
        provider=CloudProvider.AWS,
        supported_regions=[AwsRegion.US_EAST_1],
        environment=AccountEnvironment.PROD,
        aws_role_arns=AwsRoleArns(
            sumo_logic_role_arn='arn:aws:iam::061190967865:role/sumo-logic-role-SumoRole-AhsXp2UKSMT7',
        ),
    ),
    'research': CloudAccount(
        name='research',
        account_id='975482786146',
        provider=CloudProvider.AWS,
        supported_regions=[AwsRegion.US_EAST_1],
        environment=AccountEnvironment.SANDBOX,
        aws_role_arns=AwsRoleArns(sumo_logic_role_arn=''),
    ),
}
