// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) Go Code Generator. DO NOT EDIT.

package generated

import (
	"encoding/xml"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime"
	"time"
)

// MarshalXML implements the xml.Marshaller interface for type AccessPolicy.
func (a AccessPolicy) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	type alias AccessPolicy
	aux := &struct {
		*alias
		Expiry *datetime.RFC3339 `xml:"Expiry"`
		Start  *datetime.RFC3339 `xml:"Start"`
	}{
		alias:  (*alias)(&a),
		Expiry: (*datetime.RFC3339)(a.Expiry),
		Start:  (*datetime.RFC3339)(a.Start),
	}
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type AccessPolicy.
func (a *AccessPolicy) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias AccessPolicy
	aux := &struct {
		*alias
		Expiry *datetime.RFC3339 `xml:"Expiry"`
		Start  *datetime.RFC3339 `xml:"Start"`
	}{
		alias: (*alias)(a),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	if aux.Expiry != nil && !(*time.Time)(aux.Expiry).IsZero() {
		a.Expiry = (*time.Time)(aux.Expiry)
	}
	if aux.Start != nil && !(*time.Time)(aux.Start).IsZero() {
		a.Start = (*time.Time)(aux.Start)
	}
	return nil
}

// MarshalXML implements the xml.Marshaller interface for type CORSRule.
func (c CORSRule) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	start.Name.Local = "CorsRule"
	type alias CORSRule
	aux := &struct {
		*alias
	}{
		alias: (*alias)(&c),
	}
	return enc.EncodeElement(aux, start)
}

// MarshalXML implements the xml.Marshaller interface for type DequeuedMessage.
func (d DequeuedMessage) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	start.Name.Local = "QueueMessage"
	type alias DequeuedMessage
	aux := &struct {
		*alias
		ExpirationTime  *datetime.RFC7231 `xml:"ExpirationTime"`
		InsertionTime   *datetime.RFC7231 `xml:"InsertionTime"`
		TimeNextVisible *datetime.RFC7231 `xml:"TimeNextVisible"`
	}{
		alias:           (*alias)(&d),
		ExpirationTime:  (*datetime.RFC7231)(d.ExpirationTime),
		InsertionTime:   (*datetime.RFC7231)(d.InsertionTime),
		TimeNextVisible: (*datetime.RFC7231)(d.TimeNextVisible),
	}
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type DequeuedMessage.
func (d *DequeuedMessage) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias DequeuedMessage
	aux := &struct {
		*alias
		ExpirationTime  *datetime.RFC7231 `xml:"ExpirationTime"`
		InsertionTime   *datetime.RFC7231 `xml:"InsertionTime"`
		TimeNextVisible *datetime.RFC7231 `xml:"TimeNextVisible"`
	}{
		alias: (*alias)(d),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	if aux.ExpirationTime != nil && !(*time.Time)(aux.ExpirationTime).IsZero() {
		d.ExpirationTime = (*time.Time)(aux.ExpirationTime)
	}
	if aux.InsertionTime != nil && !(*time.Time)(aux.InsertionTime).IsZero() {
		d.InsertionTime = (*time.Time)(aux.InsertionTime)
	}
	if aux.TimeNextVisible != nil && !(*time.Time)(aux.TimeNextVisible).IsZero() {
		d.TimeNextVisible = (*time.Time)(aux.TimeNextVisible)
	}
	return nil
}

// MarshalXML implements the xml.Marshaller interface for type EnqueuedMessage.
func (e EnqueuedMessage) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	start.Name.Local = "QueueMessage"
	type alias EnqueuedMessage
	aux := &struct {
		*alias
		ExpirationTime  *datetime.RFC7231 `xml:"ExpirationTime"`
		InsertionTime   *datetime.RFC7231 `xml:"InsertionTime"`
		TimeNextVisible *datetime.RFC7231 `xml:"TimeNextVisible"`
	}{
		alias:           (*alias)(&e),
		ExpirationTime:  (*datetime.RFC7231)(e.ExpirationTime),
		InsertionTime:   (*datetime.RFC7231)(e.InsertionTime),
		TimeNextVisible: (*datetime.RFC7231)(e.TimeNextVisible),
	}
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type EnqueuedMessage.
func (e *EnqueuedMessage) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias EnqueuedMessage
	aux := &struct {
		*alias
		ExpirationTime  *datetime.RFC7231 `xml:"ExpirationTime"`
		InsertionTime   *datetime.RFC7231 `xml:"InsertionTime"`
		TimeNextVisible *datetime.RFC7231 `xml:"TimeNextVisible"`
	}{
		alias: (*alias)(e),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	if aux.ExpirationTime != nil && !(*time.Time)(aux.ExpirationTime).IsZero() {
		e.ExpirationTime = (*time.Time)(aux.ExpirationTime)
	}
	if aux.InsertionTime != nil && !(*time.Time)(aux.InsertionTime).IsZero() {
		e.InsertionTime = (*time.Time)(aux.InsertionTime)
	}
	if aux.TimeNextVisible != nil && !(*time.Time)(aux.TimeNextVisible).IsZero() {
		e.TimeNextVisible = (*time.Time)(aux.TimeNextVisible)
	}
	return nil
}

// MarshalXML implements the xml.Marshaller interface for type GeoReplication.
func (g GeoReplication) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	type alias GeoReplication
	aux := &struct {
		*alias
		LastSyncTime *datetime.RFC7231 `xml:"LastSyncTime"`
	}{
		alias:        (*alias)(&g),
		LastSyncTime: (*datetime.RFC7231)(g.LastSyncTime),
	}
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type GeoReplication.
func (g *GeoReplication) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias GeoReplication
	aux := &struct {
		*alias
		LastSyncTime *datetime.RFC7231 `xml:"LastSyncTime"`
	}{
		alias: (*alias)(g),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	if aux.LastSyncTime != nil && !(*time.Time)(aux.LastSyncTime).IsZero() {
		g.LastSyncTime = (*time.Time)(aux.LastSyncTime)
	}
	return nil
}

// MarshalXML implements the xml.Marshaller interface for type ListQueuesSegmentResponse.
func (l ListQueuesSegmentResponse) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	start.Name.Local = "EnumerationResults"
	type alias ListQueuesSegmentResponse
	aux := &struct {
		*alias
		Queues *[]*Queue `xml:"Queues>Queue"`
	}{
		alias: (*alias)(&l),
	}
	if l.Queues != nil {
		aux.Queues = &l.Queues
	}
	return enc.EncodeElement(aux, start)
}

// MarshalXML implements the xml.Marshaller interface for type PeekedMessage.
func (p PeekedMessage) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	start.Name.Local = "QueueMessage"
	type alias PeekedMessage
	aux := &struct {
		*alias
		ExpirationTime *datetime.RFC7231 `xml:"ExpirationTime"`
		InsertionTime  *datetime.RFC7231 `xml:"InsertionTime"`
	}{
		alias:          (*alias)(&p),
		ExpirationTime: (*datetime.RFC7231)(p.ExpirationTime),
		InsertionTime:  (*datetime.RFC7231)(p.InsertionTime),
	}
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type PeekedMessage.
func (p *PeekedMessage) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias PeekedMessage
	aux := &struct {
		*alias
		ExpirationTime *datetime.RFC7231 `xml:"ExpirationTime"`
		InsertionTime  *datetime.RFC7231 `xml:"InsertionTime"`
	}{
		alias: (*alias)(p),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	if aux.ExpirationTime != nil && !(*time.Time)(aux.ExpirationTime).IsZero() {
		p.ExpirationTime = (*time.Time)(aux.ExpirationTime)
	}
	if aux.InsertionTime != nil && !(*time.Time)(aux.InsertionTime).IsZero() {
		p.InsertionTime = (*time.Time)(aux.InsertionTime)
	}
	return nil
}

// MarshalXML implements the xml.Marshaller interface for type Queue.
func (q Queue) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	type alias Queue
	aux := &struct {
		*alias
		Metadata additionalProperties `xml:"Metadata"`
	}{
		alias: (*alias)(&q),
	}
	aux.Metadata = (additionalProperties)(q.Metadata)
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type Queue.
func (q *Queue) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias Queue
	aux := &struct {
		*alias
		Metadata additionalProperties `xml:"Metadata"`
	}{
		alias: (*alias)(q),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	q.Metadata = (map[string]*string)(aux.Metadata)
	return nil
}

// MarshalXML implements the xml.Marshaller interface for type StorageServiceProperties.
func (s StorageServiceProperties) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	type alias StorageServiceProperties
	aux := &struct {
		*alias
		CORS *[]*CORSRule `xml:"Cors>CorsRule"`
	}{
		alias: (*alias)(&s),
	}
	if s.CORS != nil {
		aux.CORS = &s.CORS
	}
	return enc.EncodeElement(aux, start)
}

// MarshalXML implements the xml.Marshaller interface for type StorageServiceStats.
func (s StorageServiceStats) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	start.Name.Local = "QueueServiceStats"
	type alias StorageServiceStats
	aux := &struct {
		*alias
	}{
		alias: (*alias)(&s),
	}
	return enc.EncodeElement(aux, start)
}

// MarshalXML implements the xml.Marshaller interface for type UserDelegationKey.
func (u UserDelegationKey) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
	type alias UserDelegationKey
	aux := &struct {
		*alias
		SignedExpiry *datetime.RFC3339 `xml:"SignedExpiry"`
		SignedStart  *datetime.RFC3339 `xml:"SignedStart"`
	}{
		alias:        (*alias)(&u),
		SignedExpiry: (*datetime.RFC3339)(u.SignedExpiry),
		SignedStart:  (*datetime.RFC3339)(u.SignedStart),
	}
	return enc.EncodeElement(aux, start)
}

// UnmarshalXML implements the xml.Unmarshaller interface for type UserDelegationKey.
func (u *UserDelegationKey) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	type alias UserDelegationKey
	aux := &struct {
		*alias
		SignedExpiry *datetime.RFC3339 `xml:"SignedExpiry"`
		SignedStart  *datetime.RFC3339 `xml:"SignedStart"`
	}{
		alias: (*alias)(u),
	}
	if err := dec.DecodeElement(aux, &start); err != nil {
		return err
	}
	if aux.SignedExpiry != nil && !(*time.Time)(aux.SignedExpiry).IsZero() {
		u.SignedExpiry = (*time.Time)(aux.SignedExpiry)
	}
	if aux.SignedStart != nil && !(*time.Time)(aux.SignedStart).IsZero() {
		u.SignedStart = (*time.Time)(aux.SignedStart)
	}
	return nil
}
