1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright 2023 Zesty Tech Ltd. All rights reserved.
// Use is subject to license terms.
//

use super::*;

#[derive(Clone, Copy, Debug, PartialEq, SerializeDisplay, DeserializeFromStr)]
#[non_exhaustive]
pub enum AzureRegion {
    EastUs,
    EastUs2,
    WestUs,
    WestUs2,
}

impl CloudLocation for AzureRegion {
    const CLOUD_VENDOR: &'static str = "Azure";
    const CLOUD_VENDOR_PREFIX: &'static str = "azure/";

    fn as_str(&self) -> &'static str {
        match self {
            Self::EastUs => "eastus",
            Self::EastUs2 => "eastus2",
            Self::WestUs => "westus",
            Self::WestUs2 => "westus2",
        }
    }
}

impl FromStr for AzureRegion {
    type Err = InvalidRegion;

    fn from_str(text: &str) -> Result<Self, Self::Err> {
        match Self::normal_region(text).as_str() {
            "eastus" => Ok(Self::EastUs),
            "eastus2" => Ok(Self::EastUs2),
            "westus" => Ok(Self::WestUs),
            "westus2" => Ok(Self::WestUs2),
            _ => Err(InvalidRegion::new(text)),
        }
    }
}

impl fmt::Display for AzureRegion {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        if f.alternate() {
            f.write_fmt(format_args!(
                "{}{}",
                Self::CLOUD_VENDOR_PREFIX,
                self.as_str()
            ))
        } else {
            self.as_str().fmt(f)
        }
    }
}