<?xml version="1.0" encoding="utf-8"?>
<Types>
  <Type>
    <Name>PSMinIO.Models.MinIOBucketInfo</Name>
    <Members>
      <ScriptProperty>
        <Name>CreatedFormatted</Name>
        <GetScriptBlock>
          $this.Created.ToString("yyyy-MM-dd HH:mm:ss")
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>SizeFormatted</Name>
        <GetScriptBlock>
          if ($this.Size -eq $null) { return "N/A" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.Size
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>
  
  <Type>
    <Name>PSMinIO.Models.MinIOObjectInfo</Name>
    <Members>
      <ScriptProperty>
        <Name>LastModifiedFormatted</Name>
        <GetScriptBlock>
          $this.LastModified.ToString("yyyy-MM-dd HH:mm:ss")
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>SizeFormatted</Name>
        <GetScriptBlock>
          if ($this.Size -eq $null) { return "N/A" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.Size
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>GetFileName</Name>
        <GetScriptBlock>
          if ($this.Name -eq $null) { return "" }
          $parts = $this.Name.Split('/')
          return $parts[$parts.Length - 1]
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>HasPresignedUrl</Name>
        <GetScriptBlock>
          return -not [string]::IsNullOrEmpty($this.PresignedUrl)
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>PresignedUrlValid</Name>
        <GetScriptBlock>
          if ($this.PresignedUrlExpiration -eq $null) { return $false }
          return $this.PresignedUrlExpiration -gt [DateTime]::UtcNow
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>

  <Type>
    <Name>PSMinIO.Models.MinIOConfiguration</Name>
    <Members>
      <ScriptProperty>
        <Name>EndpointDisplay</Name>
        <GetScriptBlock>
          if ($this.UseSSL) {
            return "https://$($this.Endpoint)"
          } else {
            return "http://$($this.Endpoint)"
          }
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>AccessKeyMasked</Name>
        <GetScriptBlock>
          if ([string]::IsNullOrEmpty($this.AccessKey)) { return "Not Set" }
          if ($this.AccessKey.Length -le 4) { return $this.AccessKey }
          return $this.AccessKey.Substring(0, 4) + "*".PadRight($this.AccessKey.Length - 4, '*')
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>SecretKeyMasked</Name>
        <GetScriptBlock>
          if ([string]::IsNullOrEmpty($this.SecretKey)) { return "Not Set" }
          return "*".PadRight($this.SecretKey.Length, '*')
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>SecurityStatus</Name>
        <GetScriptBlock>
          if ($this.SkipCertificateValidation) {
            return "SSL (Certificate Validation Disabled)"
          } elseif ($this.UseSSL) {
            return "SSL (Secure)"
          } else {
            return "HTTP (Insecure)"
          }
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>

  <Type>
    <Name>PSMinIO.Models.MinIOStats</Name>
    <Members>
      <ScriptProperty>
        <Name>TotalSizeFormatted</Name>
        <GetScriptBlock>
          if ($this.TotalSize -eq $null) { return "N/A" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.TotalSize
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>

  <!-- ChunkedTransferState Type -->
  <Type>
    <Name>PSMinIO.Models.ChunkedTransferState</Name>
    <Members>
      <ScriptProperty>
        <Name>ProgressFormatted</Name>
        <GetScriptBlock>
          return "{0:F1}%" -f $this.ProgressPercentage
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>BytesTransferredFormatted</Name>
        <GetScriptBlock>
          if ($this.BytesTransferred -eq $null) { return "0 B" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.BytesTransferred
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>TotalSizeFormatted</Name>
        <GetScriptBlock>
          if ($this.TotalSize -eq $null) { return "0 B" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.TotalSize
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>ChunkSizeFormatted</Name>
        <GetScriptBlock>
          if ($this.ChunkSize -eq $null) { return "0 B" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.ChunkSize
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>ElapsedTime</Name>
        <GetScriptBlock>
          if ($this.StartTime -eq $null) { return "Unknown" }
          $elapsed = [DateTime]::UtcNow - $this.StartTime
          return $elapsed.ToString("hh\:mm\:ss")
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>TransferStatus</Name>
        <GetScriptBlock>
          if ($this.IsComplete) {
            return "Complete"
          } elseif ($this.CompletedChunkCount -gt 0) {
            return "In Progress"
          } else {
            return "Not Started"
          }
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>RemainingChunks</Name>
        <GetScriptBlock>
          return $this.TotalChunks - $this.CompletedChunkCount
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>

  <!-- ChunkInfo Type -->
  <Type>
    <Name>PSMinIO.Models.ChunkInfo</Name>
    <Members>
      <ScriptProperty>
        <Name>SizeFormatted</Name>
        <GetScriptBlock>
          if ($this.Size -eq $null) { return "0 B" }
          $sizes = @("B", "KB", "MB", "GB", "TB", "PB")
          $index = 0
          $size = $this.Size
          while ($size -ge 1024 -and $index -lt $sizes.Length - 1) {
            $size = $size / 1024
            $index++
          }
          return "{0:F2} {1}" -f $size, $sizes[$index]
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>ChunkRange</Name>
        <GetScriptBlock>
          return "{0}-{1}" -f $this.StartByte, $this.EndByte
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>Status</Name>
        <GetScriptBlock>
          if ($this.IsCompleted) {
            return "Completed"
          } elseif ($this.RetryCount -gt 0) {
            return "Failed ({0} retries)" -f $this.RetryCount
          } else {
            return "Pending"
          }
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>
</Types>
