package smartcardemulation

import (
	"fmt"
	"strings"
)

// Code generated by cdproto-gen. DO NOT EDIT.

// ResultCode indicates the PC/SC error code. This maps to: PC/SC Lite:
// https://pcsclite.apdu.fr/api/group__ErrorCodes.html Microsoft:
// https://learn.microsoft.com/en-us/windows/win32/secauthn/authentication-return-values.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ResultCode
type ResultCode string

// String returns the ResultCode as string value.
func (t ResultCode) String() string {
	return string(t)
}

// ResultCode values.
const (
	ResultCodeSuccess            ResultCode = "success"
	ResultCodeRemovedCard        ResultCode = "removed-card"
	ResultCodeResetCard          ResultCode = "reset-card"
	ResultCodeUnpoweredCard      ResultCode = "unpowered-card"
	ResultCodeUnresponsiveCard   ResultCode = "unresponsive-card"
	ResultCodeUnsupportedCard    ResultCode = "unsupported-card"
	ResultCodeReaderUnavailable  ResultCode = "reader-unavailable"
	ResultCodeSharingViolation   ResultCode = "sharing-violation"
	ResultCodeNotTransacted      ResultCode = "not-transacted"
	ResultCodeNoSmartcard        ResultCode = "no-smartcard"
	ResultCodeProtoMismatch      ResultCode = "proto-mismatch"
	ResultCodeSystemCancelled    ResultCode = "system-cancelled"
	ResultCodeNotReady           ResultCode = "not-ready"
	ResultCodeCancelled          ResultCode = "cancelled"
	ResultCodeInsufficientBuffer ResultCode = "insufficient-buffer"
	ResultCodeInvalidHandle      ResultCode = "invalid-handle"
	ResultCodeInvalidParameter   ResultCode = "invalid-parameter"
	ResultCodeInvalidValue       ResultCode = "invalid-value"
	ResultCodeNoMemory           ResultCode = "no-memory"
	ResultCodeTimeout            ResultCode = "timeout"
	ResultCodeUnknownReader      ResultCode = "unknown-reader"
	ResultCodeUnsupportedFeature ResultCode = "unsupported-feature"
	ResultCodeNoReadersAvailable ResultCode = "no-readers-available"
	ResultCodeServiceStopped     ResultCode = "service-stopped"
	ResultCodeNoService          ResultCode = "no-service"
	ResultCodeCommError          ResultCode = "comm-error"
	ResultCodeInternalError      ResultCode = "internal-error"
	ResultCodeServerTooBusy      ResultCode = "server-too-busy"
	ResultCodeUnexpected         ResultCode = "unexpected"
	ResultCodeShutdown           ResultCode = "shutdown"
	ResultCodeUnknownCard        ResultCode = "unknown-card"
	ResultCodeUnknown            ResultCode = "unknown"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *ResultCode) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch ResultCode(s) {
	case ResultCodeSuccess:
		*t = ResultCodeSuccess
	case ResultCodeRemovedCard:
		*t = ResultCodeRemovedCard
	case ResultCodeResetCard:
		*t = ResultCodeResetCard
	case ResultCodeUnpoweredCard:
		*t = ResultCodeUnpoweredCard
	case ResultCodeUnresponsiveCard:
		*t = ResultCodeUnresponsiveCard
	case ResultCodeUnsupportedCard:
		*t = ResultCodeUnsupportedCard
	case ResultCodeReaderUnavailable:
		*t = ResultCodeReaderUnavailable
	case ResultCodeSharingViolation:
		*t = ResultCodeSharingViolation
	case ResultCodeNotTransacted:
		*t = ResultCodeNotTransacted
	case ResultCodeNoSmartcard:
		*t = ResultCodeNoSmartcard
	case ResultCodeProtoMismatch:
		*t = ResultCodeProtoMismatch
	case ResultCodeSystemCancelled:
		*t = ResultCodeSystemCancelled
	case ResultCodeNotReady:
		*t = ResultCodeNotReady
	case ResultCodeCancelled:
		*t = ResultCodeCancelled
	case ResultCodeInsufficientBuffer:
		*t = ResultCodeInsufficientBuffer
	case ResultCodeInvalidHandle:
		*t = ResultCodeInvalidHandle
	case ResultCodeInvalidParameter:
		*t = ResultCodeInvalidParameter
	case ResultCodeInvalidValue:
		*t = ResultCodeInvalidValue
	case ResultCodeNoMemory:
		*t = ResultCodeNoMemory
	case ResultCodeTimeout:
		*t = ResultCodeTimeout
	case ResultCodeUnknownReader:
		*t = ResultCodeUnknownReader
	case ResultCodeUnsupportedFeature:
		*t = ResultCodeUnsupportedFeature
	case ResultCodeNoReadersAvailable:
		*t = ResultCodeNoReadersAvailable
	case ResultCodeServiceStopped:
		*t = ResultCodeServiceStopped
	case ResultCodeNoService:
		*t = ResultCodeNoService
	case ResultCodeCommError:
		*t = ResultCodeCommError
	case ResultCodeInternalError:
		*t = ResultCodeInternalError
	case ResultCodeServerTooBusy:
		*t = ResultCodeServerTooBusy
	case ResultCodeUnexpected:
		*t = ResultCodeUnexpected
	case ResultCodeShutdown:
		*t = ResultCodeShutdown
	case ResultCodeUnknownCard:
		*t = ResultCodeUnknownCard
	case ResultCodeUnknown:
		*t = ResultCodeUnknown
	default:
		return fmt.Errorf("unknown ResultCode value: %v", s)
	}
	return nil
}

// ShareMode maps to the |SCARD_SHARE_*| values.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ShareMode
type ShareMode string

// String returns the ShareMode as string value.
func (t ShareMode) String() string {
	return string(t)
}

// ShareMode values.
const (
	ShareModeShared    ShareMode = "shared"
	ShareModeExclusive ShareMode = "exclusive"
	ShareModeDirect    ShareMode = "direct"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *ShareMode) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch ShareMode(s) {
	case ShareModeShared:
		*t = ShareModeShared
	case ShareModeExclusive:
		*t = ShareModeExclusive
	case ShareModeDirect:
		*t = ShareModeDirect
	default:
		return fmt.Errorf("unknown ShareMode value: %v", s)
	}
	return nil
}

// Disposition indicates what the reader should do with the card.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-Disposition
type Disposition string

// String returns the Disposition as string value.
func (t Disposition) String() string {
	return string(t)
}

// Disposition values.
const (
	DispositionLeaveCard   Disposition = "leave-card"
	DispositionResetCard   Disposition = "reset-card"
	DispositionUnpowerCard Disposition = "unpower-card"
	DispositionEjectCard   Disposition = "eject-card"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *Disposition) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch Disposition(s) {
	case DispositionLeaveCard:
		*t = DispositionLeaveCard
	case DispositionResetCard:
		*t = DispositionResetCard
	case DispositionUnpowerCard:
		*t = DispositionUnpowerCard
	case DispositionEjectCard:
		*t = DispositionEjectCard
	default:
		return fmt.Errorf("unknown Disposition value: %v", s)
	}
	return nil
}

// ConnectionState maps to |SCARD_*| connection state values.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ConnectionState
type ConnectionState string

// String returns the ConnectionState as string value.
func (t ConnectionState) String() string {
	return string(t)
}

// ConnectionState values.
const (
	ConnectionStateAbsent     ConnectionState = "absent"
	ConnectionStatePresent    ConnectionState = "present"
	ConnectionStateSwallowed  ConnectionState = "swallowed"
	ConnectionStatePowered    ConnectionState = "powered"
	ConnectionStateNegotiable ConnectionState = "negotiable"
	ConnectionStateSpecific   ConnectionState = "specific"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *ConnectionState) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch ConnectionState(s) {
	case ConnectionStateAbsent:
		*t = ConnectionStateAbsent
	case ConnectionStatePresent:
		*t = ConnectionStatePresent
	case ConnectionStateSwallowed:
		*t = ConnectionStateSwallowed
	case ConnectionStatePowered:
		*t = ConnectionStatePowered
	case ConnectionStateNegotiable:
		*t = ConnectionStateNegotiable
	case ConnectionStateSpecific:
		*t = ConnectionStateSpecific
	default:
		return fmt.Errorf("unknown ConnectionState value: %v", s)
	}
	return nil
}

// ReaderStateFlags maps to the |SCARD_STATE_*| flags.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ReaderStateFlags
type ReaderStateFlags struct {
	Unaware     bool `json:"unaware"`
	Ignore      bool `json:"ignore"`
	Changed     bool `json:"changed"`
	Unknown     bool `json:"unknown"`
	Unavailable bool `json:"unavailable"`
	Empty       bool `json:"empty"`
	Present     bool `json:"present"`
	Exclusive   bool `json:"exclusive"`
	Inuse       bool `json:"inuse"`
	Mute        bool `json:"mute"`
	Unpowered   bool `json:"unpowered"`
}

// ProtocolSet maps to the |SCARD_PROTOCOL_*| flags.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ProtocolSet
type ProtocolSet struct {
	T0  bool `json:"t0"`
	T1  bool `json:"t1"`
	Raw bool `json:"raw"`
}

// Protocol maps to the |SCARD_PROTOCOL_*| values.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-Protocol
type Protocol string

// String returns the Protocol as string value.
func (t Protocol) String() string {
	return string(t)
}

// Protocol values.
const (
	ProtocolT0  Protocol = "t0"
	ProtocolT1  Protocol = "t1"
	ProtocolRaw Protocol = "raw"
)

// UnmarshalJSON satisfies [json.Unmarshaler].
func (t *Protocol) UnmarshalJSON(buf []byte) error {
	s := string(buf)
	s = strings.TrimSuffix(strings.TrimPrefix(s, `"`), `"`)

	switch Protocol(s) {
	case ProtocolT0:
		*t = ProtocolT0
	case ProtocolT1:
		*t = ProtocolT1
	case ProtocolRaw:
		*t = ProtocolRaw
	default:
		return fmt.Errorf("unknown Protocol value: %v", s)
	}
	return nil
}

// ReaderStateIn [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ReaderStateIn
type ReaderStateIn struct {
	Reader                string            `json:"reader"`
	CurrentState          *ReaderStateFlags `json:"currentState"`
	CurrentInsertionCount int64             `json:"currentInsertionCount"`
}

// ReaderStateOut [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/SmartCardEmulation#type-ReaderStateOut
type ReaderStateOut struct {
	Reader     string            `json:"reader"`
	EventState *ReaderStateFlags `json:"eventState"`
	EventCount int64             `json:"eventCount"`
	Atr        string            `json:"atr"`
}
