/*
 * auto generated by tools(注意:千万不要手动修改本文件)
 * MusicContainer
 */
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace OCES.Audio
{
[Serializable]
public partial class MusicContainer : IBinarySerializable
{
	/// <summary>
	/// 一定不要出现循环
	/// </summary>
	public uint Id { get; set; }

	/// <summary>
	/// 1000000以下的是musicId 以上的是ContainerId
	/// </summary>
	public List<uint> Segments { get; set; }

	/// <summary>
	/// 0 = 随机播放
	/// 1 = 顺序播放
	/// 2 = 混合播放
	/// 3 = 切换播放
	/// </summary>
	public ContainerType ContainerType { get; set; }

	/// <summary>
	/// 0 = 步进
	/// 1 = 持续
	/// </summary>
	public bool ContainerPlayMode { get; set; }

	/// <summary>
	/// sequence: 间隔时间(s)
	/// </summary>
	public ushort StrategyParam { get; set; }

	/// <summary>
	/// -1 = 无限循环
	/// 0 = 不循环
	/// >= 1 按次数循环
	/// </summary>
	public short LoopCount { get; set; }

	/// <summary>
	/// 速度
	/// 可以是小数
	/// </summary>
	public float Bpm { get; set; }

	/// <summary>
	/// 拍号
	/// 采用德国体系定义
	/// </summary>
	public string TimeSig { get; set; }

	/// <summary>
	/// 多少小节为一个grid
	/// </summary>
	public int Grid { get; set; }


	public void DeSerialize(BinaryReader reader)
	{
		Id = reader.ReadUInt32();
		var segmentsCount = reader.ReadInt32();
		if (segmentsCount > 0)
		{
			Segments = new List<uint>();
			for (int i = 0; i < segmentsCount; i++)
			{
				Segments.Add(reader.ReadUInt32());
			}
		}
		else
		{
			Segments = null;
		}
		ContainerType = (ContainerType)reader.ReadByte();
		ContainerPlayMode = reader.ReadBoolean();
		StrategyParam = reader.ReadUInt16();
		LoopCount = reader.ReadInt16();
		Bpm = reader.ReadSingle();
		TimeSig = reader.ReadString();
		Grid = reader.ReadInt32();
	}

	public void Serialize(BinaryWriter writer)
	{
		writer.Write(Id);
		if (Segments == null || Segments.Count == 0)
		{
			writer.Write(0);
		}
		else
		{
			writer.Write(Segments.Count);
			foreach (var t in Segments)
			{
				writer.Write(t);
			}
		}
		writer.Write((byte)ContainerType);
		writer.Write(ContainerPlayMode);
		writer.Write(StrategyParam);
		writer.Write(LoopCount);
		writer.Write(Bpm);
		writer.Write(TimeSig);
		writer.Write(Grid);
	}
}

[Serializable]
public partial class MusicContainerConfig : IBinarySerializable
{
	Dictionary<uint,MusicContainer> m_musicContainerInfos = new();
	List<MusicContainer> m_musicContainerInfoList;

	public List<MusicContainer> MusicContainerList()
	{
		this.m_musicContainerInfoList ??= new List<MusicContainer>(this.m_musicContainerInfos.Values);
		return this.m_musicContainerInfoList;
	}

	public void DeSerialize(BinaryReader reader)
	{
		int count = reader.ReadInt32();
		for (int i = 0; i < count; i++)
		{
			MusicContainer tempData = new();
			tempData.DeSerialize(reader);
			this.m_musicContainerInfos.Add(tempData.Id, tempData);
		}
	}

	public void Serialize(BinaryWriter writer)
	{
		writer.Write(this.m_musicContainerInfos.Count);
		foreach (MusicContainer musicContainer in this.m_musicContainerInfos.Values)
		{
			musicContainer.Serialize(writer);
		}
	}

	public MusicContainer QueryById(uint id)
	{
		return this.m_musicContainerInfos.GetValueOrDefault(id);
	}
}
}
