1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
pub use super::*;
use frame_support::pallet_prelude::*;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

use scale_info::TypeInfo;

pub type NftCollectionOf = Nft::PossibleCollections;
pub use Nft::ItemInfoOf;

#[derive(Clone, Encode, Decode, PartialEq, Eq, TypeInfo, Copy)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub enum AssetStatus {
	EDITING,
	REVIEWING,
	VOTING,
	ONBOARDED,
	FINALISING,
	FINALISED,
	PURCHASED,
	REJECTED,
	SLASH,
	CANCELLED,
}

#[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebugNoBound, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Asset<T: Config> {
	/// Asset status
	pub status: AssetStatus,
	/// Asset creation block
	pub(super) created: BlockNumberOf<T>,
	/// NFT infos
	pub(super) infos: ItemInfoOf<T>,
	/// NFT Price
	pub price: Option<BalanceOf<T>>,
	/// Representative
	pub representative: Option<T::AccountId>,
	/// Tenants
	pub tenants: Vec<T::AccountId>,
	/// Proposal hash
	pub proposal_hash: T::Hash,
	/// Maximum number of tenants for this asset
	pub max_tenants: u8,
}

impl<T: Config> Asset<T> {
	pub fn new(
		collection: T::NftCollectionId,
		item: T::NftItemId,
		infos: ItemInfoOf<T>,
		price: Option<BalanceOf<T>>,
		max_tenants: u8
	) -> DispatchResult {
		let status = AssetStatus::EDITING;
		let created = <frame_system::Pallet<T>>::block_number();
		let house = Asset::<T> {
			status,
			created,
			infos,
			price,
			representative: None,
			tenants: Default::default(),
			proposal_hash: Default::default(),
			max_tenants,
		};
		Houses::<T>::insert(collection, item, house);

		Ok(())
	}
}

#[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebugNoBound, TypeInfo)]
#[scale_info(skip_type_params(T))]
//#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct VotingCalls<T: Config> {
	/// Asset creation block
	pub(super) reject_edit: Box<T::Prop>,
	/// NFT infos
	pub(super) reject_destroy: Box<T::Prop>,
	/// NFT Price
	pub(super) democracy_status: Box<T::Prop>,
	///After positive Investor vote status
	pub(super) after_vote_status: Box<T::Prop>,
}

impl<T: Config> VotingCalls<T> {
	pub fn new(collection: T::NftCollectionId, item: T::NftItemId) -> DispatchResult {
		let nbr: u32 = 0;
		let call: T::Prop = Call::<T>::do_something { something: nbr }.into();

		let calls = VotingCalls::<T> {
			reject_edit: Box::new(call.clone()),
			reject_destroy: Box::new(call.clone()),
			democracy_status: Box::new(call.clone()),
			after_vote_status: Box::new(call),
		};
		Vcalls::<T>::insert(collection, item, calls);
		Ok(())
	}
}