Class Auteur {
	[validatenotnullorempty()][String]$Name = 'Nicolas BAUDIN'
	[ValidatePattern("^[a-z0-9.-_]+@[a-z0-9.-_]+`.[a-z]{2,4}")]
	[String]$Email = 'nicolas.baudin@powershell.com'
	[ValidateRange(1,160)][int]$age
    [int]$BornYear
	[ValidateRange(01053,98821)][int]$CodePostal

    Auteur($NewAge) {
			$this.UpdateAge($NewAge)
	}
    [void]UpdateAge($Age){
        $this.age = $Age
        $Now = Get-Date
        $this.BornYear = $Now.AddYears(-$age).Year
    }
    [int]GetNewBornYears($Age){
        $Now = Get-Date
        $NewBornYear = $Now.AddYears(-$age).Year
        Return $NewBornYear
    }
    [String]GetCodePostal([int]$Codepostale){
        If ($Codepostale -eq 44000){
            Return 'Nantes'
        }Else{
            Return 'Inconnu'
        }
    }<#
    [int]GetCodePostal([string]$Codepostale){
        If ($Codepostale -eq 'Nantes'){
            Return 44000
        }Else{
            Return 00000
        }
    }#>
    [int]GetCodePostal([string]$Codepostale){
        $cp = 00000
        Switch ($Codepostale){
            'Nantes' {$cp = 44000}
            'Paris' {$cp = 75001}
        }
        Return $cp
    }
}
$Me = [Auteur]::New(25)

$Me.Email = 'nico.baudin@lol.lo'

$Pattern = "^[a-z0-9.-_]+@[a-z0-9.-_]+`.[a-z]{2,4}"
$mail = 'nicolas.baudin@vesta-host.com'

$mail -match $Pattern

'nicolas.baudin@vesta-host.com' -match "^[a-z0-9.-_]+@[a-z0-9.-_]+`.[a-z]{2,4}"

Enum CodeLivre {
    RessourceInformatique = 12
    ExpertIT = 8
    Epsilon = 32
}
[CodeLivre]$Celivre = 1

Class Auteur1 {
	[validatenotnullorempty()][String]$Name
	[ValidatePattern("^[a-z0-9.-_]+@[a-z0-9.-_]+`.[a-z]{2,4}")]	[String]$Email
	[ValidateRange(1,160)][int]$age
    [int]$BornYear
	[ValidateRange(01053,98821)][int]$CodePostal
    Static $Edition = 'ExpertIT'

    Auteur1($NewAge) {
        Write-Host 'Appel du constructeur 1'
		$this.UpdateAge($NewAge)
	}
    Auteur1([String]$NewName,
            [String]$NewEmail,
            [int]$NewAge,
            [int]$CodePostal){
        Write-Host 'Appel du constructeur 2'
        $this.Name = $NewName
        $this.CodePostal = $CodePostal
        $this.Email = $NewEmail
        $this.UpdateAge($NewAge)

    }
    [void]UpdateAge($Age){
        $this.age = $Age
        $Now = Get-Date
        $this.BornYear = $Now.AddYears(-$age).Year
    }
    [void]Show(){
		Write-Host "Mon édition est $($this::Edition)"
	}

}
Class Auteur2 {
	[validatenotnullorempty()][String]$Name
	[ValidatePattern("^[a-z0-9.-_]+@[a-z0-9.-_]+`.[a-z]{2,4}")]	[String]$Email
	[ValidateRange(1,160)][int]$age
    [int]$BornYear
	[ValidateRange(01053,98821)][int]$CodePostal
    Static $Edition

    Static Auteur2 (){
        Write-host 'Appel du constructeur statique'
        [Auteur2]::Edition = 'ExpertIT'
    }
    Auteur2($NewAge) {
        Write-Host 'Appel du constructeur non statique'
		$this.UpdateAge($NewAge)
	}
    Auteur2([String]$NewName,
            [String]$NewEmail,
            [int]$NewAge,
            [int]$CodePostal){
        Write-Host 'Appel du constructeur 2'
        $this.Name = $NewName
        $this.CodePostal = $CodePostal
        $this.Email = $NewEmail
        $this.UpdateAge($NewAge)

    }
    [void]UpdateAge($Age){
        $this.age = $Age
        $Now = Get-Date
        $this.BornYear = $Now.AddYears(-$age).Year
    }
    Static [void]Show(){
		Write-Host "Mon édition est $([Auteur2]::Edition)"
	}

}
[Auteur2]::Show()
$Me = [Auteur2]::New(25)
$Me = [Auteur2]::New(30)

[Auteur]::Edition

################Scope #######################

$Var = 7

function TestScope {
    $Var = 44
    [Scope]::ShowVar()
}

class Scope {

    Static [void]ShowVar(){
        Write-host $script:Var
    }
}
TestScope

$Var=77
Class ScopeProp { 
    $Count = $Var 
    Static $B=$Var
}
$Me = [ScopeProp]::New()
$Me.Count
[ScopeProp]::B
$Var = 44
$Me1 = [ScopeProp]::New()
$Me1.Count
$Me1::B
[ScopeProp]::B
$Me.Count
[ScopeProp]::B = 20
$Me.Count
[ScopeProp]::B
$Me1.Count
$Me1::B
#Variable static incrémenter lors de l'initialisation de la classe. Et non lors d'un simple appel ou de l'appel d'un constructeur.
#Contraire sur une variable non static


###Héritage###

Class Computer {
    [String]$Name
    [String]$OS
    Rename([String]$NewName){
        Rename-Computer -ComputerName $this.Name `
        -NewName $NewName
    }
    Computer([String]$Name,[String]$OS) {
        $this.Name = $Name
        $this.OS = $OS
    }
}
Class Server : Computer{
    [String]$Role
    Server([String]$Name,[string]$OS,[string]$Role):base($Name,$OS){
        $this.Role = $Role
    }
}

$MyCompute = [Computer]::New('PC-Generic','Windows')
$MyServer = [Server]::New('SRVWIN2K16','Win Srv 2016','IIS')
$Mycompute
$MyServer
