"""
Some structures for unit tests.

(in particular in attrdeftest and structuretest).
"""

#c Copyright 2008-2025, the GAVO project <gavo@ari.uni-heidelberg.de>
#c
#c This program is free software, covered by the GNU GPL.  See the
#c COPYING file in the source distribution.

from gavo import base
from gavo.base.structure import Structure


class Child(Structure):
	name_ = "child"
	_fab = base.UnicodeAttribute("fab", default="empty", copyable=True)


class Child2(Structure):
	name_ = "child2"
	_fab = base.UnicodeAttribute("romp")


class Color(Structure):
	name_ = "color"
	_r = base.IntAttribute("r", 255, copyable=True)
	_g = base.IntAttribute("g", 255, copyable=True)
	_b = base.FloatAttribute("b", 255, copyable=True)

class CopyableColor(Color):
	_orig = base.OriginalAttribute(forceType=Color)


class Foo(Structure):
	name_ = "foo"
	_color = base.StructAttribute(
		"color",
		childFactory=Color,
		copyable=True,
		default=None)
	_name = base.UnicodeAttribute("name", default=base.Undefined, copyable=True)
	_content = base.DataContent(copyable=True)


class Foos(Structure):
	name_ = "foos"
	_content = base.StructListAttribute("plups", Foo)


class Bla(Structure):
	name_ = "bla"
	_att1 = base.ListOfAtomsAttribute("items",
		itemAttD=base.IntAttribute("item"), copyable=True)


class Palette(Structure):
	name_ = "pal"
	_map = base.StringListAttribute("map", copyable=True)
	_flavor = base.UnicodeAttribute("flavor")
	_colors = base.StructListAttribute("colors", childFactory=CopyableColor,
		copyable=True)
	_foo = base.StructListAttribute("foos", childFactory=Foo, copyable=True)


class PalCollection(Structure):
	name_ = "pals"
	_pals = base.StructListAttribute("pals", childFactory=Palette)


class Image(Structure):
	name_ = "image"
	_pal = base.ReferenceAttribute("pal",
		default=True,
		forceType=Palette,
		copyable=True)
	_calib = base.ListOfAtomsAttribute("calibs",
		itemAttD=base.UnicodeAttribute("calib"), copyable=True)
	_orig = base.OriginalAttribute()
	_maps = base.DictAttribute("maps", keyName="from", copyable=True,
		itemAttD=base.UnicodeAttribute("map"))
	_revs = base.DictAttribute("rev", keyName="to", inverted=True)


class Root(Structure):
	name_ = "root"
	_ims = base.StructListAttribute("ims", childFactory=Image, copyable=True)
	_pals = base.StructListAttribute("pals", childFactory=Palette,
		copyable=True)
