package types

type Account struct {
	AliCloudRole              *AliCloudRoleArn `yaml:"alicloud-role,omitempty"` // must be pointer. If not MarshalYAML and UnmarshalYAML does not work
	AwsRole                   *AwsRoleArn      `yaml:"aws-role,omitempty"`      // must be pointer. If not MarshalYAML and UnmarshalYAML does not work
	AzureClientId             *AzureClientId   `yaml:"azure-client,omitempty"`
	GcpProject                string           `yaml:"gcp-project,omitempty"`
	WorkdloadIdentityProvider string           `yaml:"gcp-wip,omitempty"`
	ServiceAccount            string           `yaml:"gcp-sa,omitempty"`
}

func FromAwsArn(arn string) (*Account, error) {
	role, err := FromRoleArnString(arn)
	if err != nil {
		return nil, err
	}
	return &Account{
		AwsRole: role,
	}, nil
}

func FromAliCloudArn(arn string) (*Account, error) {
	role, err := StringToAliCloudRoleArn(arn)
	if err != nil {
		return nil, err
	}
	return &Account{
		AliCloudRole: role,
	}, nil
}

func FromAzureClientId(tenantId, subscriptionId, clientid string) (*Account, error) {
	return &Account{
		AzureClientId: &AzureClientId{
			TenantId:       tenantId,
			SubscriptionId: subscriptionId,
			ClientId:       clientid,
		},
	}, nil
}
