/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ---------------------------------------------------------------------
 *
 * Portions of this file were modified and ported to Vala by Victor Vintorez in 2026.
 * These modifications are licensed under the European Union Public License (EUPL),
 * Version 1.2 or later. You may obtain a copy of the License at:
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 */

using GLib;

namespace MaterialColorUtilities {
	/**
	 * An intermediate concept between the key color for a UI theme, and a full color scheme. 5 sets of
	 * tones are generated, all except one use the same hue as the key color, and all vary in chroma.
	 *
	 * @deprecated Use {@link dynamiccolor.DynamicScheme} for color
	 *     scheme generation. Use {@link palettes.CorePalettes} for core
	 *     palettes container class.
	 */
	public sealed class CorePalette : Object {
		public TonalPalette a1 { get; private set; }
		public TonalPalette a2 { get; private set; }
		public TonalPalette a3 { get; private set; }
		public TonalPalette n1 { get; private set; }
		public TonalPalette n2 { get; private set; }
		public TonalPalette error { get; private set; }

		/**
		 * Create key tones from a color.
		 *
		 * @param argb ARGB representation of a color
		 * @deprecated Use {@link dynamiccolor.DynamicScheme} for color
		 *     scheme generation. Use {@link palettes.CorePalettes} for
		 *     core palettes container class.
		 */
		public static CorePalette of(int argb) {
			return new CorePalette(argb, false);
		}

		/**
		 * Create content key tones from a color.
		 *
		 * @param argb ARGB representation of a color
		 * @deprecated Use {@link dynamiccolor.DynamicScheme} for color
		 *     scheme generation. Use {@link palettes.CorePalettes} for
		 *     core palettes container class.
		 */
		public static CorePalette content_of(int argb) {
			return new CorePalette(argb, true);
		}

		private CorePalette(int argb, bool is_content) {
			Hct hct = Hct.from_int(argb);
			double hue = hct.hue;
			double chroma = hct.chroma;
			if (is_content) {
				this.a1 = TonalPalette.from_hue_and_chroma(hue, chroma);
				this.a2 = TonalPalette.from_hue_and_chroma(hue, chroma / 3.0);
				this.a3 = TonalPalette.from_hue_and_chroma(hue + 60.0, chroma / 2.0);
				this.n1 = TonalPalette.from_hue_and_chroma(hue, Math.fmin(chroma / 12.0, 4.0));
				this.n2 = TonalPalette.from_hue_and_chroma(hue, Math.fmin(chroma / 6.0, 8.0));
			} else {
				this.a1 = TonalPalette.from_hue_and_chroma(hue, Math.fmax(48.0, chroma));
				this.a2 = TonalPalette.from_hue_and_chroma(hue, 16.0);
				this.a3 = TonalPalette.from_hue_and_chroma(hue + 60.0, 24.0);
				this.n1 = TonalPalette.from_hue_and_chroma(hue, 4.0);
				this.n2 = TonalPalette.from_hue_and_chroma(hue, 8.0);
			}
			this.error = TonalPalette.from_hue_and_chroma(25, 84.0);
		}
	}
}
