# Copyright (c) 2022, JINGROW
# See license.txt
from __future__ import annotations

from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch

import jingrow
from jingrow.tests.utils import JingrowTestCase

from jcloud.jcloud.pagetype.cluster.test_cluster import create_test_cluster
from jcloud.jcloud.pagetype.virtual_machine_image.virtual_machine_image import (
	VirtualMachineImage,
)

if TYPE_CHECKING:
	from jcloud.jcloud.pagetype.cluster.cluster import Cluster


@patch.object(VirtualMachineImage, "client", new=MagicMock())
@patch.object(VirtualMachineImage, "after_insert", new=MagicMock())
def create_test_virtual_machine_image(
	ip: str | None = None,
	cluster: Cluster = None,
	series: str = "m",
) -> VirtualMachineImage:
	"""Create test Virtual Machine Image pg"""
	if not ip:
		ip = jingrow.mock("ipv4")
	if not cluster:
		cluster = create_test_cluster()
	from jcloud.jcloud.pagetype.virtual_machine.test_virtual_machine import (
		create_test_virtual_machine,
	)

	vm = create_test_virtual_machine(cluster=cluster, series=series)

	return jingrow.get_pg(
		{
			"pagetype": "Virtual Machine Image",
			"virtual_machine": vm.name,
			"region": vm.region,
			"status": "Available",
			"image_id": "ami-1234567890",
			"mariadb_root_password": "password",
		}
	).insert(ignore_if_duplicate=True)


class TestVirtualMachineImage(JingrowTestCase):
	pass
