using System;
using System.Collections.Generic;

using CommonHelpers.WASM;
using AFXUI;

using BookRegistry.Client.Shared;
using BookRegistry.Client.Components;
using BookRegistry.Client.DB;

namespace BookRegistry.Client {

//**************************************************************************************************
enum BookSorting {
   Name, ISBN, ReleaseYear, AuthorName, CategoryName, GenreName, PublisherName, SeriesName
} // BookSorting
//**************************************************************************************************


//**************************************************************************************************
class BookSortingInfo {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public BookSorting Key { get; }
public string Name { get; }

//==================================================================================================

public BookSortingInfo(BookSorting key) =>
   Name = KeyToName( Key = key );

//==================================================================================================

public static IReadOnlyList<BookSortingInfo> Items
{
   get {
      if ( _Items_ == null )
      {
         var list = new List<BookSortingInfo>();
         list.Add( new BookSortingInfo( BookSorting.Name ) );
         list.Add( new BookSortingInfo( BookSorting.ISBN ) );
         list.Add( new BookSortingInfo( BookSorting.ReleaseYear ) );
         list.Add( new BookSortingInfo( BookSorting.AuthorName ) );
         list.Add( new BookSortingInfo( BookSorting.CategoryName ) );
         list.Add( new BookSortingInfo( BookSorting.GenreName ) );
         list.Add( new BookSortingInfo( BookSorting.PublisherName ) );
         list.Add( new BookSortingInfo( BookSorting.SeriesName ) );
         _Items_ = list.ToArray();
      }
      return _Items_;
   }
}

//--------------------------------------------------------------------------------------------------

static string KeyToName(BookSorting key)
{
   switch ( key )
   {
   case BookSorting.Name:
      return "by book-name";
   case BookSorting.ISBN:
      return "by ISBN";
   case BookSorting.ReleaseYear:
      return "by year of release";
   case BookSorting.AuthorName:
      return "by author name";
   case BookSorting.CategoryName:
      return "by category name";
   case BookSorting.GenreName:
      return "by genre name";
   case BookSorting.PublisherName:
      return "by publisher name";
   case BookSorting.SeriesName:
      return "by series name";
   default:
      throw HAssertionFailure.DEAD_BRANCH();
   }
}

//==================================================================================================

static BookSortingInfo[]? _Items_;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // BookSortingInfo
//**************************************************************************************************

} // BookRegistry.Client
