/*
OPEN OUTCRY API

# Introduction This API is documented in **OpenAPI 3.0 format**.  This API the following operations: * Retrieve a list of available instruments * Retrieve a list of executed trades  # Basics * API calls have to be secured with HTTPS. * All data has to be submitted UTF-8 encoded. * The reply is sent JSON encoded.

API version: 1.0.0
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package api

import (
	"encoding/json"
	"fmt"
)

// checks if the TradingAccount type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &TradingAccount{}

// TradingAccount struct for TradingAccount
type TradingAccount struct {
	Id          string                     `json:"id"`
	Instruments []TradingAccountInstrument `json:"instruments"`
}

type _TradingAccount TradingAccount

// NewTradingAccount instantiates a new TradingAccount object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewTradingAccount(id string, instruments []TradingAccountInstrument) *TradingAccount {
	this := TradingAccount{}
	this.Id = id
	this.Instruments = instruments
	return &this
}

// NewTradingAccountWithDefaults instantiates a new TradingAccount object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewTradingAccountWithDefaults() *TradingAccount {
	this := TradingAccount{}
	return &this
}

// GetId returns the Id field value
func (o *TradingAccount) GetId() string {
	if o == nil {
		var ret string
		return ret
	}

	return o.Id
}

// GetIdOk returns a tuple with the Id field value
// and a boolean to check if the value has been set.
func (o *TradingAccount) GetIdOk() (*string, bool) {
	if o == nil {
		return nil, false
	}
	return &o.Id, true
}

// SetId sets field value
func (o *TradingAccount) SetId(v string) {
	o.Id = v
}

// GetInstruments returns the Instruments field value
func (o *TradingAccount) GetInstruments() []TradingAccountInstrument {
	if o == nil {
		var ret []TradingAccountInstrument
		return ret
	}

	return o.Instruments
}

// GetInstrumentsOk returns a tuple with the Instruments field value
// and a boolean to check if the value has been set.
func (o *TradingAccount) GetInstrumentsOk() ([]TradingAccountInstrument, bool) {
	if o == nil {
		return nil, false
	}
	return o.Instruments, true
}

// SetInstruments sets field value
func (o *TradingAccount) SetInstruments(v []TradingAccountInstrument) {
	o.Instruments = v
}

func (o TradingAccount) MarshalJSON() ([]byte, error) {
	toSerialize, err := o.ToMap()
	if err != nil {
		return []byte{}, err
	}
	return json.Marshal(toSerialize)
}

func (o TradingAccount) ToMap() (map[string]interface{}, error) {
	toSerialize := map[string]interface{}{}
	toSerialize["id"] = o.Id
	toSerialize["instruments"] = o.Instruments
	return toSerialize, nil
}

func (o *TradingAccount) UnmarshalJSON(bytes []byte) (err error) {
	// This validates that all required properties are included in the JSON object
	// by unmarshalling the object into a generic map with string keys and checking
	// that every required field exists as a key in the generic map.
	requiredProperties := []string{
		"id",
		"instruments",
	}

	allProperties := make(map[string]interface{})

	err = json.Unmarshal(bytes, &allProperties)

	if err != nil {
		return err
	}

	for _, requiredProperty := range requiredProperties {
		if _, exists := allProperties[requiredProperty]; !exists {
			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

	varTradingAccount := _TradingAccount{}

	err = json.Unmarshal(bytes, &varTradingAccount)

	if err != nil {
		return err
	}

	*o = TradingAccount(varTradingAccount)

	return err
}

type NullableTradingAccount struct {
	value *TradingAccount
	isSet bool
}

func (v NullableTradingAccount) Get() *TradingAccount {
	return v.value
}

func (v *NullableTradingAccount) Set(val *TradingAccount) {
	v.value = val
	v.isSet = true
}

func (v NullableTradingAccount) IsSet() bool {
	return v.isSet
}

func (v *NullableTradingAccount) Unset() {
	v.value = nil
	v.isSet = false
}

func NewNullableTradingAccount(val *TradingAccount) *NullableTradingAccount {
	return &NullableTradingAccount{value: val, isSet: true}
}

func (v NullableTradingAccount) MarshalJSON() ([]byte, error) {
	return json.Marshal(v.value)
}

func (v *NullableTradingAccount) UnmarshalJSON(src []byte) error {
	v.isSet = true
	return json.Unmarshal(src, &v.value)
}
