using System.Collections.Generic;
using Net.Eagle0.Eagle.Views;

namespace eagle {
    public static class BattalionUtils {
        public static readonly IComparer<BattalionView> BattalionComparer =
                new _BattalionComparer();

        private class _BattalionComparer : Comparer<BattalionView> {
            public override int Compare(BattalionView x, BattalionView y) {
                if (x.Type.CompareTo(y.Type) != 0) {
                    return x.Type.CompareTo(y.Type);
                } else if (x.Size.CompareTo(y.Size) != 0) {
                    return -x.Size.CompareTo(y.Size);
                } else if (
                        (x.Training.GetValueOrDefault() + x.Armament.GetValueOrDefault())
                                .CompareTo(
                                        y.Training.GetValueOrDefault() +
                                        y.Armament.GetValueOrDefault()) != 0) {
                    return -(x.Training.GetValueOrDefault() + x.Armament.GetValueOrDefault())
                                    .CompareTo(
                                            y.Training.GetValueOrDefault() +
                                            y.Armament.GetValueOrDefault());
                } else {
                    return 0;
                }
            }
        }
    }
}