﻿CREATE PROCEDURE [session].[CreateSession]
	@SessionName [session].[SessionName],
	@Player1Name [user].[UserName],
	@InitialBoardStateDocument [session].[JsonDocument]
AS
BEGIN

SET NOCOUNT ON
SET XACT_ABORT ON

BEGIN TRANSACTION
	INSERT INTO [session].[Session] ([Name], Player1Id)
	SELECT
		@SessionName,
		Id
	FROM [user].[User]
	WHERE [Name] = @Player1Name;

	INSERT INTO [session].[BoardState] (Document, SessionId) 
	VALUES
		(@InitialBoardStateDocument, SCOPE_IDENTITY());
COMMIT

END