from flask_appbuilder import Model
from sqlalchemy import Column, Integer, String, ForeignKey, Text, Date
from flask import Markup
from sqlalchemy.orm import relationship


class MatchType(Model):
	id = Column(Integer, primary_key=True)
	match_type = Column(String(50), unique=True, nullable=False)

	def __repr__(self):
		return self.match_type


class PassReason(Model):
	id = Column(Integer, primary_key=True)
	reason = Column(String(50), unique=True, nullable=False)

	def __repr__(self):
		return self.reason


class opportunityReport(Model):
	id = Column(Integer, primary_key=True)
	notif_source = Column(String)
	notif_date = Column(Date)
	notif_url = Column(String)
	notif_details = Column(Text)
	oppty_desc = Column(String)
	oppty_source = Column(String)
	oppty_date = Column(Date)
	oppty_url = Column(String)
	match_id = Column(Integer, ForeignKey('match_type.id'))
	match = relationship("MatchType")
	naics = Column(String)
	pop = Column(String)
	setaside = Column(String)
	pass_id = Column(Integer, ForeignKey('pass_reason.id'))
	pass_reason = relationship("PassReason")

	def __repr__(self):
		return self.notif_details

	def description(self):
		return Markup(f'')

	def notif_link(self):
		return Markup(f'<a href={self.notif_url} target=_blank>link</a>')

	def oppty_link(self):
		#return Markup(f'[link]: {self.oppty_url}')
		return Markup(f'<a href={self.oppty_url} target=_blank>link</a>')

	def notif_details_link(self):
		#return Markup(f'[link]: {self.oppty_url}')
		return Markup(f'<a href={self.oppty_url} target=_blank>{self.notif_details}</a>')